SAN DIEGO — Julie Ertz came in off the bench and scored in the 89th minute and the United States overcame a late three-goal deficit to beat Brazil 4-3 on Sunday night in the Tournament of Nations.

The United States was in danger of losing for the fourth time this year before the three-goal flurry in about nine minutes.

advertisement | advertise on newsday

Two minutes after Brazil’s Andressinha scored on a free kick in the 78th minute for her second goal of the game, Christen Press countered to make it 3-2.

Press fed Megan Rapinoe for a spectacular running blast that tied it in the 85th minute, and Ertz put the Americans ahead four minutes later. Ertz is using her married name after playing as Julie Johnston.

The United States was coming off a 1-0 loss to Australia in the team’s Tournament of Nations opener in Seattle on Thursday night.