The U.S. men’s national soccer team is going to the knockout stage of the World Cup, not because it defeated — or even tied — Germany on Thursday afternoon. The Americans are headed to the round of 16 next week because of the capital they accrued over 11 compelling days and the series of events that unfolded more than 1,000 miles apart on the final day of group play.

They lost the game, 1-0, but won the right to remain at soccer’s quadrennial jamboree by virtue of a superior goal differential over Portugal in Group G, the so-called Group of Death.

For 90 minutes, though, Arena Pernambuco was inundated by rain and tension. With the Americans heading toward defeat, the other group match would determine their future.

Had Ghana, the greatest threat to U.S. advancement, scored another goal against Portugal in Brasilia, the Americans likely would have been eliminated. Instead, Portuguese superstar Cristiano Ronaldo scored late to all but kill Ghana’s chances of swiping second place.

When the final whistle sounded here, the U.S. players lingered on the sopped field for a few moments, unsure whether they could begin celebrating. The news from Brasilia then began to spread: Ghana had lost. The video board confirmed it for anyone still in the dark. Thousands of drenched U.S. supporters rejoiced.

“The Group of Death, I died a few times up there,” U.S. Soccer Federation President Sunil Gulati said after joining the squad from his suite.

Germany (2-0-1, seven points) rode Thomas Müller’s 55th-minute goal — his fourth of the tournament — to win the quartet and earn a round-of-16 meeting with Algeria on Monday in Porto Alegre.

The United States (1-1-1, four) was next because of an even goal differential: four goals for, four against. Portugal (1-1-1) settled for third with a minus-three differential. So close to overtaking the Americans, Ghana (0-2-1) finished last. Had the Black Stars won 2-1 instead of losing 2-1, they would have won the second tiebreaker with the United States (goals scored).

“We didn’t really have an idea what was going on in the other game [until] I think with about 10 minutes left, [goalkeeper] Tim Howard came up and said a score,” center back Omar Gonzalez said.

It seemed appropriate the Americans’ fate was not determined until after the match ended. Since arriving, they have provided a slew of late-game drama: scoring an 86th-minute goal to defeat Ghana, conceding an equalizer with seconds left against Portugal and then probing for a late goal against Germany before waiting out the other outcome.

“Last game’s draw felt like a loss, and today’s loss felt like a win,” Gonzalez said. “It’s pretty weird, but our mission from the very beginning was to get to the next round.”

To their credit, they put themselves in position to advance by accumulating points in the first two matches.

“It would have been nice to celebrate a win,” captain Clint Dempsey said. “But to get to the knockout stage, it doesn’t matter how it happens.”

For the first time in U.S. history, it has happened in consecutive World Cups. Four years ago in South Africa, the United States won the group ahead of England but lost to Ghana in the round of 16.

“Once the group is done, another tournament actually starts,” said Jurgen Klinsmann, the German-born U.S. coach. “The knockout stage is a completely different ballgame.”

Thursday’s theater was eerily similar to how the Americans advanced in 2002, when they lost the group finale to Poland but advanced because Portugal lost to South Korea in a game played simultaneously.

“It’s a special day,” said midfielder Jermaine Jones, who suffered what he believes is a broken nose after colliding with teammate Alejandro Bedoya in the second half. “We lose the game, but it’s a nice loss. Trust me, it’s nice.”

Despite the torrent of rain, the field was in decent condition and did not have the pronounced impact initially feared during pregame inspections. It certainly did not bother the Germans, who set the terms from the first minute and moved the ball with purpose and efficiency for much of the match.

The Americans created few quality scoring chances.

“We had a little bit too much respect [for Germany] the first 20 to 25 minutes,” Klinsmann said. “Then I think nerves settled a little bit.”

Ten minutes after intermission, though, Germany went in front. Howard made a fine save on Per Mertesacker’s header but the rebound fell to Müller, who drove an 18-yard shot into the right corner.

Losing was one thing; losing by multiple goals would cloud the United States’ outlook. The defense stood firm, and the margin remained intact.

Meanwhile in Brasilia, Ghana had drawn even with Portugal. If the U.S.-Germany score held and Ghana struck again, the Americans would be out.

Updates were relayed to the U.S. bench. And when Ronaldo, who had provided the sensational assist in the closing seconds against the Americans on Sunday, scored his first goal of the tournament, a sense of relief washed over the U.S. delegation.

“When it was 1-1 there and 1-0 in our game, it was obviously a very dangerous situation,” Gulati said. “Nerve-racking but mission accomplished.”