Panama had frustrated an initially dominant Mexico team after Carlos Salcedo's 42nd-minute own goal cancelled out Roberto Alvarado's opener on Tuesday.
However, Jose Juan Macias came off the bench to restore Mexico's lead 15 minutes from the end and Rodolfo Pizarro made sure of the win in the second minute of stoppage time in the Group B clash.
Mexico, who crushed Bermuda 5-1 in their Nations League opener, controlled proceedings from the outset against Panama at Estadio Azteca.
El Tri put the ball in the back of the net in the 23rd minute after Carlos Rodriguez's shot was parried into the path of Hirving Lozano but it was ruled out for offside.
Lozano was in the thick of the action again as he rattled the crossbar with a ferocious long-range attempt four minutes later.
Mexico did get their goal a minute later, when Alvarado curled a shot past Panama goalkeeper Luis Mejia.
After Lozano flashed a shot wide of the post approaching the interval, Panama equalised against the run of black with three minutes remaining prior to half-time.
The sliding Salcedo attempted to block a cross into the six-yard box, but the Mexico defender unfortunately turned the ball into his own net.
Panama surged forward and almost took a 53rd-minute lead as Mexico goalkeeper Raul Gudino stood tall to deny Jose Rodriguez.
¡Hirving Lozano queda tendido en el terreno de juego!— TUDN USA (@TUDNUSA) October 16, 2019
No puede seguir en el partido ¡Alarmas en el Tri!#México | #PasiónyOrgullo | #PasiónPorTUSelección
But Mexico eased the tension within the stadium as the spirited Panama side came unstuck in the 75th minute after Macias received the ball on the edge of the area and fired a shot through the hands of Mejia, while Pizarro sealed the points in the 92nd minute with a shot into the top corner.
What does it mean? El Tri stay top
It was not straightforward, but Mexico made it two wins from two matches in Group B on Tuesday. The home side did not have it their own way, though they now find themselves three points clear.
Napoli left sweating over Lozano
Serie A title hopefuls Napoli will be praying Lozano's injury is not too serious. The Mexico star was carried off the field on a stretcher with 24 minutes remaining due to an ankle injury.
Lozano limping but leaves the Estadio Azteca without assistance.— Jon Arnold (@ArnoldcommaJon) October 16, 2019
Seems like a good sign, but we'll have to wait and see what the people who actually diagnose him say... https://t.co/UUBE1Nu4JK
Panama impress away from home
Not much was expected from Panama, who had only won three of their previous 20 games. However, the visitors were great value after recovering from an early deficit, albeit in fortuitous circumstances.
Mexico and Panama will do battle again on November 15, with the latter welcoming El Tri to their country.