Six days after suffering a shock defeat to Mexico, the defending champions found themselves a goal down to Sweden and in need of a big turnaround.
Turn the game around they did, though, levelling up through Marco Reus and then winning the match thanks to a Toni Kroos free kick in the fifth minute of added time, despite being reduced to 10 men following Jerome Boateng's red card.
Just a second win in eight matches since October places Germany, who take on South Korea in their next outing, level on points with Sweden in second and means that it is all still to play for next week.
Knowing that just a point would leave their hopes of progression hanging in the balance, Germany started the gripping match in a dominant fashion.
Julian Draxler, brought into the side in place of Mesut Ozil as one of four changes following the 1-0 loss to Mexico last week, turned Joshua Kimmich's cross goalwards but saw it blocked in front of the target.
Kimmich, Draxler and Reus were having plenty of joy in the final third, though possession did not equate to chances and the flow of the game soon changed.
Berg and his teammates were furious with the Polish officials, though, as they felt that Boateng shoved the striker as he was about to make contact, yet VAR was not even consulted.
The Blue-Yellow knew that they would get further chances on the counter, and so it proved a little over a third of the way through as Viktor Claesson sent the ball over the top for Ola Toivonen, who controlled it with his chest then lofted it over the onrushing Neuer.
Germany came close to a quick response, with Robin Olsen pushing aside substitute Ilkay Gundogan's 25-yarder and then, thanks to some help from Mikael Lustig, thwarting Thomas Muller from the rebound.
Sweden were left wondering how they went into the break with just the one goal to their name, however, as Claesson failed to make the most of a glorious chance inside the box following another swift move, and Berg was somehow denied by a fine Neuer save from the final act of an action-packed opening 45 minutes.
After making a second change at the break, bringing on Mario Gomez for Draxler, Die Mannschaft needed less than three minutes of the second half to level up - Reus diverting Timo Werner's cutback past Olsen with his knee.
For the first time in 548 minutes Sweden had to pick the ball out of the back of their net, and it was then a case of holding on as Muller sent a header wide and Jonas Hector got in a low shot on target.
The German attacking was relentless and, unlike in the first half, the Scandinavians did not appear to have an out-ball and were dropping deeper and deeper.
Gomez was guilty of missing a good opportunity from right under the crossbar, and Olsen was needed to stop Andreas Granqvist - the matchwinner against South Korea last time out - from turning the ball into his own net.
Sweden had a brief moment of respite when winning a corner, from which Emil Forsberg volleyed the ball at Neuer, but the momentum was with Germany and Werner really should have converted his big chance from eight yards.
Just when the pressure looked as though it would tell, referee Szymon Marciniak reached into his pocket to show Boateng a second yellow card for his challenge on Berg.
Ending the game with just two defenders on the field, Germany toiled as Gomez's close-range header was turned over the bar and Julian Brandt's edge-of-the-box shot hit the inside of the post.
Yet an incredible late twist saw Kroos bend a free kick into the far corner from the final meaningful act of the match, meaning that Germany have to match Sweden's result against Mexico, with goal difference - currently identical - potentially coming into play.
GERMANY (4-2-3-1): Neuer; Kimmich, Boateng, Rudiger, Hector (Brandt 87'); Rudy (Gundogan 31'), Kroos; Reus, Muller, Draxler (Gomez 46'); Werner
SWEDEN (4-4-2): Olsen; Lustig, Lindelof, Granqvist, Augustinsson; Claesson (Durmaz 74'), Larsson, Ekdal, Forsberg; Toivonen (Guidetti 78'), Berg (Thelin 90')