The United States recorded a 3-0 win over Nicaragua on Saturday to secure the top spot in Group B at the CONCACAF Gold Cup.
Joe Corona and Kelyn Rowe struck either side of half-time at FirstEnergy Stadium in Cleveland, Ohio.
However, Dom Dwyer and Corona saw second-half spot-kicks saved and USA appeared set to finish second to Panama in Group B.
But Matt Miazga scored an 88th-minute header - his first international goal - to lift them into top spot after Luis Fernando Copete had been sent off for Nicaragua.
That saw USA avoid Costa Rica in the quarter-finals thanks to having scored more goals than Panama.
Bruce Arena, whose team had already booked a last-eight spot, opted to field a completely different starting XI than the one that edged Martinique 3-2.
Nicaragua made four changes as Cyril Errington, Bismarck Veliz, Bryan Garcia and Luis Peralta replaced Manuel Rosas, Carlos Chavarria, Eulises Pavon and Erick Tellez from the team beaten 2-1 by Panama.
USA were on top early as Rowe in particular looked dangerous, the midfielder firing a volley straight at Nicaragua goalkeeper Justo Lorente in the seventh minute.
Dwyer and Graham Zusi also went close, the latter surging into the area before shooting straight at Lorente.
An opener always appeared to be coming for USA and it arrived nine minutes prior to half-time.
Alejandro Bedoya burst clear down the right before his cross found Corona, who twisted and turned inside the area and saw his strike deflect into the bottom corner.
Nicaragua were only able to create half-chances and USA's dominance continued after the break, but they were denied twice from the penalty spot.
Dwyer was dragged down by Marlon Lopez for the first spot-kick, but the forward's penalty was too narrow and at a good height for Lorente.
USA did double their lead in the 56th minute.
Rowe was played through by Bedoya and the New England Revolution man beat Lorente at his near post for his first international goal.
Another spot-kick followed for USA after a Daniel Cadena handball and Corona stepped up, but Lorente got down low to his right to keep it out.
After Copete picked up a second yellow card in the 85th minute, Zusi drifted in a delightful set-piece for Miazga to head in at the back post for what was a crucial goal for USA.