In a hot-tempered encounter that on more than one occasion descended into disgraceful scenes, Mexico somehow kept their Gold Cup hopes alive courtesy of two Andrés  Guardado penalties to beat Panama 2-1 in Wednesday’s semifinal. The nine-time champions had been headed for defeat after a Panama side that was down to 10 men for the vast majority of the encounter took the lead through Román Torres’ goal just past the hour mark. But for the second match running, Mexico were given the benefit of a controversial penalty.

Cruelly it was Torres who was harshly adjudged to have handled in the box in the 89th minute, and, after a ridiculous delay of more than 10-minutes during which there were protests from players and objects thrown from the stands, Guardado kept his nerve to force extra time. Another penalty was to follow just before the halfway point in the added 30 minutes, but this time there was little to debate when Carlos Vela went down under Harold Cummings’ challenge. Seconds later, Mexico’s dependable captain sent his side into Sunday’s final against Jamaica.

But Mexico can count themselves hugely fortunate to be in the showpiece encounter in Philadelphia, rather than taking on bitter foes the United States in the third-place playoff. Despite seeing forward Luis Tejada harshly shown a red card just 25 minutes in, Panama coped comfortably with what little threat Mexico provided.

Having played out a goalless draw with Guatemala in the group stage and with Honduras ahead of the tournament, the problems were all-too familiar for El Tri. A startling predictability and lack of ingenuity going forward was complemented by a worrying lack of intensity in what was such a key match. A well-organized Panama side would have been well worth a repeat of their 2013 Gold Cup semifinal victory over the same opponents. Instead, Panama will get a chance for revenge for its final defeat to the U.S. two years ago, but it will be for the dubious honor of third place rather than for its first ever Gold Cup trophy. Mexico and coach Miguel Herrera get to fight another day to a title that is of vital importance for them, not least because it would earn them a playoff with the United States for a place at the 2017 Confederations Cup. To secure that, they will surely have to produce an improved performance on what they produced on Wednesday and, indeed through much of the tournament.

Building on a more encouraging second-half showing against Costa Rica in the semifinals, Mexico began firmly on top in Atlanta. But they still failed to seriously test Panama goalkeeper Jaime Penedo, and were dealt an early blow when Carlos Vela was given a yellow card for sticking an elbow into the midriff of Aníbal Godoy, which means he will mess the final. Another controversial incident was not long in arriving. Tejada certainly made contact with Francisco “Maza” Rodriguez’s face as he jumped for the ball, but the contact was with his forearm, not his elbow, and there looked little evidence that he swung it in a dangerous manner. Still a red card was produced, which led to a melee and Tejada taking more than three minutes to leave the field, while Panama players physically confronted referee Mark Geiger.

Already without fellow key forward Blas Pérez due to injury, and now down a man, the odds looked stacked against Panama. However, they were to be given precious little to worry about by Mexico. Indeed, of the two goalkeepers it was Mexico’s Guillermo Ochoa who was the busier before halftime. Despite Mexico switching to 4-4-2 at the interval with the introduction of Carlos Esquivel for Oswaldo Alanis, the pattern continued in the second half. And just before the hour mark, Mexico were punished for their listlessness. From Eric Davis’ corner, Torres rose above Rodriguez at the far post and headed down and past Ochoa to give Panama a lead that at that stage was far from surprising.

There continued to look little sign that Mexico would be able to find a breakthrough to stay alive in the competition. But for the second match running, a fortunate refereeing decision was to come to their aid right at the death. Torres fell on the ball seemingly accidentally with his arm in the box, a penalty was awarded and madness ensued both on the field and in the stands. Amid the huge controversy, Guardado deserves huge credit for, just as against Costa Rica, holding his nerve in the most pressurized circumstances.

With Mexico reprieved and Panama believing they had seen their dreams stolen away, El Tri were the stronger team in extra time. And Guarado again proved the hero to secure a victory that provided little to cherish in a contest that, for all the wrong reasons, including Panama players rushing to confront the referee at the final whistle, will live long in the memory.