Megan Rapinoe (left) celebrates her goal wth Alex Morgan (13). (Sam Navarro-USA TODAY Sports)

The top-ranked U.S. women’s national team dropped a 2-1 decision to No. 3 Germany in an international friendly, snapping the Americans’ 71-game home unbeaten streak on Thursday night.

The loss was the first on home soil for the USWNT in five years. The Americans’ last home defeat came on July 27, 2017, a 1-0 setback to Australia in the Tournament of Nations.

Megan Rapinoe scored for the USA in front of 16,971 fans at DRV PNK Stadium in Fort Lauderdale, a match that saw two goals find the net in the final five minutes of regulation.

Four minutes after Rapinoe tallied, Paulina Krumbiegel recorded the game-winner for the visitors in the 89th minute.

The match opened with U.S. repelling an energetic Germany, which recently topped its UEFA qualifying group for the 2023 World Cup in Australia and New Zealand and finished runner-up at the 2022 UEFA Women’s EURO. Goalkeeper Casey Murphy thwarted the early chances and shots that.

Midway through the opening half, the USWNT found its footing and came close to scoring several times. A slick move by Rose Lavelle beat her defender on the endline in the 35th minute with a dazzling nutmeg to put her in on goal where her cross was pushed away by Germany goalkeeper Merle Frohms. The rebound was put back on goal by Lindsey Horan, only for the ball to hit the underside of the bar, bounce down onto the goal line and into Frohms’ arms.

Minutes later, after Mallory Pugh burst in on goal on a long run, beat a defender to the inside and then drew a great save out a charging Frohms, Horan flashed a header just wide of the left post off a cross from right back Sofia Huerta.

Captaining the USA for the fourth time this year, Horan was denied a penalty kick just before halftime when she was chopped down by German forward Alexandra Popp in the box only to have referee Odette Hamilton wave play on. The teams went to the break tied at 0-0.

Two bounces at the beginning of the second half went against the U.S. The first saw Horan smack an acrobatic volley off the left post. Having escaped going behind yet again, Germany capitalized on the counterattack and Klara Bühl’s bending shot hit the Americans’ right post and bounced off the back of the diving Murphy before rolling across the goal line for a 1-0 Germany lead in the 52nd minute.

It was ruled as an own goal.

The USA pressed forward throughout the half as head coach Vlatko Andonovski emptied his bench. The changes paid off in the 85th minute when Alex Morgan blocked a Germany clearance attempt. She collected the loose ball and crossed low into the middle of the penalty area. An unmarked Rapinoe, who subbed for Pugh, lashed the ball home to draw the score level at 1-1. It was Rapinoe’s first goal for the USA in more than a year and the 63rd goal of her international career. Playing in her 199th cap with the USA, Morgan tallied her first assist of the year and the 47th of her international career.

The USA comeback was stymied in the 89th minute as a pressing U.S. team fell victim to a counterattack that was converted by Krumbiegel for the game-winner.

The USA and Germany will meet again in the former’s final match of 2022 at Red Bull Arena in Harrison, N.J. on Sunday (5 p.m. ET, ESPN).