CHESTER, Pa. — Backup goalkeeper Luis Mejia saved two penalty kicks in a shootout, and an inspired Panama team ended a trying week with a medal, beating the United States in the CONCACAF Gold Cup third-place game Saturday.

Panama won the shootout 3-2 after extra time ended with the score 1-1.

Mejia saved DaMarcus Beasley’s shot in the fifth round in what might have been the veteran defender’s last game for the national team.

Panama was on the verge of beating Mexico in Wednesday’s semifinals despite being down to 10 men but was called for a disputed hand ball in the area. Mexico converted the penalty kick in stoppage time then scored on another penalty kick in extra time for the 2-1 win.

The Panamanian federation’s president later alleged the match was fixed, and players were seen arriving at PPL Park on Saturday wearing T-shirts that read, “Dignity isn’t bought.”

It was another shaky performance by the Americans, who were stunned by Jamaica in the semifinals and had their worst Gold Cup finish since losing to Colombia, an invited guest, during a shootout in the 2000 quarterfinals.

Roberto Nurse scored for Panama in the 55th minute, and Clint Dempsey evened the game in the 70th with his tournament-high seventh goal.

With the shootout tied 2-2 in the fourth round, Mejia saved captain Michael Bradley’s shot. Harold Cummings then beat Brad Guzan inside the left post to put the pressure on Beasley to keep the U.S. alive.

Panama was missing several key players because of injury or suspension, including its top goalkeeper. But it dominated play against a sluggish U.S. team, with 11 shots on goal to the Americans’ two in regulation.

After a U.S. player had to clear a shot off the line to save a goal for the second time, Panama finally broke through moments later. Nurse took the ball in the area but had two defenders around him. He faked out John Brooks, the young center back who had a rough tournament. Nurse was alone in front of the goal for what seemed like several seconds as he lined up the shot to beat Guzan.

Jurgen Klinsmann had planned to bring Beasley in during the second half, but the coach was presumably hoping the U.S. would be leading. With the Americans instead trailing and scuffling, Klinsmann used DeAndre Yedlin and Dempsey as subs in the 60th minute, and they combined for the tying goal.

Yedlin’s speed created the chance when he ran onto and chested down a long ball from Bradley. That drew the goalkeeper and two defenders to him, and Yedlin spun around and flicked it to Dempsey, who slid into the ball from 16 yards.

Beasley came on to start extra time.

In all six of its Gold Cup games, Panama went up 1-0 only to give up the equalizer in the second half and end regulation tied 1-1.

It was the Americans’ first shootout since they beat Panama in the 2005 Gold Cup final.