[Up Next: Follow our live coverage of England v. Belgium]

The goal, five minutes into second-half added time, and only moments before the final whistle, gives Germany a strong shot of advancing to the round of 16 on a night that began with the team facing elimination. It came on a night when the Germans produced twice as many shots as Sweden, and enjoyed almost three times the possession, but still had to battle back from a 1-0 deficit at halftime, and then, in the final part of the game, play a man down after Jérôme Boateng was sent off with a red card.

But Germany found a way to survive, with Kroos’s goal, on a finely orchestrated free-kick play, giving it a vital three points in its four-team group. Germany is now even with Sweden and three points behind Mexico. A victory in its final group game, against winless South Korea, would put it in a very solid position to advance. A draw against Sweden would have kept Germany’s chances to advance alive, but would have made things far more precarious.

“We never lost hope that we could turn the tide and win this match,” said Germany Coach Joachim Löw, who six days ago boldly guaranteed his team would reach the knockout rounds. He said the winning goal was “obviously a bit of luck, but it is also a sign of us believing.”

The winner was, in fact, a stunner: a free kick on the left side that Kroos rolled a yard ahead to his teammate Marco Reus, who had scored Germany’s opening goal in the 54th minute. Reus stopped the ball and stepped back as Kroos took his full windup and curled a shot that went over two defenders, around goalkeeper Robin Olsen and then inside the right post.

The goal, and the victory, completely altered the dynamic at this World Cup for the Germans, who raced to Kroos at the corner flag and smothered him with a mix of joy and relief. A listless loss to Mexico in its opener had left Germany in an uncomfortable position when it took the field at Fisht Stadium: It understood that a defeat against the Swedes, who had won their first game, would guarantee that Germany, the defending champion, would somehow be out of the World Cup after the first round.