Matt Miazga scored in the 88th minute to cap the United States' 3-0 win over Nicaragua in Cleveland on Saturday, ensuring the Americans topped CONCACAF Gold Cup Group B on goals scored.
The U.S. needed to win by three goals to ensure they matched the plus-four goal difference of Panama, who beat Martinique 3-0 earlier in the day. They won the group on the next tiebreaker, goals scored, 7-6.
Though Joe Corona and Kelyn Rowe had the U.S. up by two goals, a pair of missed penalties had the Americans staring at a quarterfinal test against Costa Rica until Miazga headed home late.
The result means the U.S. will face a third-place finisher, most likely to be El Salvador, in Philadelphia on Wednesday, rather than the more formidable Los Ticos, who will instead play Panama.
Nicaragua had a surprise early chance when Dax McCarty was caught in possession by Luis Galeano, who could not keep his shot on target.
The U.S. recovered quickly, though, and a minute later, Alejandro Bedoya and Dwyer both had shots blocked in the box.
In the 20th minute, Graham Zusi intercepted a pass and made a long run into the box, but his shot was straight at goalkeeper Justo Lorente, and five minutes later Chris Pontius's attempted bicycle kick flew wide of the post.
The breakthrough came in the 36th minute as Bedoya cut the ball back to the top of the box for Corona, who danced around two defenders before putting a deflected shot just inside the post.
Despite taking the lead, the Americans still needed two more goals to avoid finishing second in the group, and they got a lifeline when Dom Dwyer was hauled down in the box by Marlon Lopez.
Dwyer had a chance to become the third player to score in his first three U.S. games, but Lorente dived to his right to stop the penalty.
The U.S. got its second goal in the 56th minute when the ball fell to Bedoya, who showed great vision to lay the ball off for the onrushing Rowe to score at the near post.
And five minutes later the U.S. had another chance to score from the penalty spot after Daniel Cadena was whistled for handling the ball, but again Lorente made a huge save, this time denying Corona.
Bruce Arena made a pair of changes, bringing on Paul Arriola and Jordan Morris for Rowe and Corona, but it was Nicaragua who had the next chance as Juan Barrera forced Bill Hamid to make a diving save.
Juan Agudelo came on for Dwyer in the U.S.'s third change, and chances for a third goal got better when Nicaragua's Luis Copete was sent off with a second yellow card in the 85th minute.
The crucial goal came from a set piece three minutes later as Miazga headed in Zusi's lofted cross to ensure the U.S. topped the group.