For a short time, just over half an hour including the half-time interval, Germany were on their way out of the World Cup.
For much longer they were in deep trouble, unable to find the winner, teetering on the brink and vulnerable.
Then, five minutes into stoppage time and down to 10 men, up stepped Toni Kroos to fire a free-kick from wide on the left swerving past the dive of Sweden goalkeeper Robin Olsen.
Toni Kroos snatched victory right at the death for Germany against Sweden, scoring a fantastic curling free-kick in injury time
With Germany’s World Cup hopes in danger, Kroos stepped up right at the death to fire Germany to all three points
Kroos pictured firing home the dramatic late winner for Germany past Sweden goalkeeper Robin Olsen
28-year-old Olsen watches Kroos’ free-kick nestle into his net in injury-time of what was a tense clash
The Real Madrid midfielder is mobbed by his jubilant Germany team-mates after sealing the all-important three points
Mario Gomez shows off his elation after Germany sealed the 2-1 victory at the death on Saturday against Sweden
The Germans were a picture of relief after Kroos’ winner and now go into their final group game in a strong position
Sebastian Larsson rages as Sweden let in a last-minute goal, which puts them in a precarious position going into the last game
Germany 4-2-3-1: Neuer 6; Kimmich 6.5, Boateng 5.5, Rudiger 6, Hector 6 (Brandt 87); Rudy 6.5 (Gundogan 31 min, 7), Kroos 7.5; Muller 6.5, Reus 7, Draxler 5 (Gomez 46, 6.5); Werner 6.5.
Goals: Reus, Kroos
Off: Boateng 82
Manager: Joachim Low 6
Sweden 4-4-2: Olsen 7; Lustig 6.5, Lindelof 6.5, Granqvist 7, Augustinsson 6; Claesson 7.5 (Durmaz 74), Larsson 6, Ekdal 8, Forsberg 6; Berg 6.5 (Kiese 90), Toivenen 7 (Guidetti 78).
Bookings: Ekdal, Guidetti, Lustig
Manager: Janne Andersson 6.5
Ref: Szymon Marciniak (Poland) 5
Germany breathed again and the crisis washed away.
Initially they had trailed to a goal by Ola Toivonen and it might have been more and their ruthless efficiency had vanished, replaced by reckless abandon.
Just as against Mexico in Moscow, the result which triggered a rare crisis amid German ranks and fuel the curse of the champions.
This century, Spain, Italy and France have all failed to make it through the group stage when defending the title.
Marco Reus equalised early in the second half and they gave everything in search of a second but Sweden defended well and rode their luck.
Timo Werner skied a good late chance and Robin Olsen turned over a header by Mario Gomez with a fine reflex save.
Julian Brandt struck a post with a sweet left footer in stoppage time and Werner could not turn the rebound on target.
Jerome Boateng was sent off for a second yellow card after the intervention of the video assistant referee.
Then Kroos, at fault for Sweden’s goal in the first half, made amends in the most remarkable fashion and the holders are back in the game.
When Low spoke of trust and confidence on the eve of the game, he did not sound like a manager set to tear up his team to satisfy his critics but there were four changes.
Marco Reus equalised for the Germans immediately after the restart as he kneed home from close range
Sweden goalkeeper Olsen and his team-mates watch on as Reus’ effort nestles into the bottom corner
The Borussia Dortmund man celebrates his goal while the Sweden players display their disappointment in the second half
Reus celebrates with Thomas Muller after equalising for Joachim Low’s side in the 47th minute on Saturday evening
The 29-year-old is congratulated by Gomez, who was brought on at half-time for winger Julian Draxler
Among them Ozil, always the subject of so much debate when Germany lose, a familiar story for anyone who has followed the story of his career at Arsenal.
Sami Khedira was also out as Low injected pace into the team with Marco Reus taking Ozil’s place and Sebastian Rudy called into midfield to partner Toni Kroos.
Toni Rudiger replaced Mats Hummels who has a neck problem, Jonas Hector returned at left back and Germany came roaring out like a team with a point to prove.
Full-backs were pushed forward and the tempo turned to breathless as early attempts by Julian Draxler and Hector were blocked and the Swedes scrambled around, deep in their own penalty area making desperate blocks and hurried clearances.
Sweden were without centre-half Pontus Jansson, one of three players struggling with sickness ahead of the game, but they survived the early storm and, just like Mexico, caused big problems for the holders on the break.
Germany were fortunate to escape what appeared to be a certain penalty when Boateng barged into Marcus Berg as he prepared to shoot, having been released by a pass from Viktor Claesson.
Jerome Boateng receives his marching orders in the 81st minute after picking up a second yellow card of the night
Boateng is shown his first yellow card in the 70th minute by referee Szymon Marciniak on Saturday evening
Gomez smashes the ball over the crossbar from close-range but was later ajudged to have been offside
Germany manager Low watches on nervously from the sidelines with his side’s World Cup hopes in danger
Mikael Lustig challenges for the ball with Reus and Jonas Hector during the second half at the Fisht Olympic Stadium
Kroos takes a corner in the second half with Germany desperately searching for a winner against Sweden
The clumsy challenge looked like a foul at the time and it looked like a foul on the television no matter how much it was slowed down and replayed.
Boateng had been caught out and was trying to disturb Berg but barged him over and the striker prepared to shoot.
The Swedes went berserk when it became clear Polish referee Szymon Marciniak did not award a penalty.
Even as Germany carried the ball down the other end of the pitch, the game existed in a state suspended animation as 50,000 spectators waited for an intervention from the video assistant referee.
That did not come either, another question for the VAR system to consider, but the incident knocked Germany’s confidence and they lost their rhythm.
Then they lost Rudy, accidentally kicked in the face by Toivonen, and forced off as the medics tried to stem the blood gushing from his busted nose.
It was then Sweden who took the lead, another wonderful move slicing through the white shirts on the turnover when Kroos lost the ball cheaply in midfield.
Claesson picked out Toivonen and the splendid pass was matched by a touch with his chest and the finish lobbed over Neuer from an angle while under pressure from Rudiger.
Ola Toivonen opened the scoring for Sweden with a fantastic chip over Manuel Neuer in the 32nd minute
Toivonen watches on in anticipation while Bayern Munich goalkeeper Neuer desperately runs back to try and clear the ball
The 31-year-old wheels off to celebrate after brilliantly putting Sweden ahead against the reigning world champions
Toivonen celebrates in front of the jubilant Sweden supporters after giving Sweden the advantage on Saturday
Celtic defender Lustig jumps on the goalscorer as Sweden celebrate taking the lead in the World Cup clash
Reus shows off his dejection after Germany went behind during the opening period on the weekend
This time the Swedes celebrated.
Rudy was unable to continue and was replaced by Ilkay Gundogan, who made an instant impression with a long-range effort which took a deflection and forced a brilliant save from Robin Olsen.
Goalkeeper Olsen and Mikael Lustig combined to prevent Thomas Muller from bundling the rebound into the net.
Still, the Germans wobbled at the back.
Claesson’s touch let him down in front of goal and Neuer took off to his right to reach a flashing header by Berg from Sebastian Larsson’s expert free-kick delivery.
Low sent on Mario Gomez to replace Draxler at half-time and his team started the second half as they started the first.
This time, however, they found the net. Werner’s low cross from the left evaded Gomez at the near post and Reus arrived to turn it past Olsen, despite making scruffy contact on the ball with the inside of his left knee.
Germany did not care about the aesthetics by this point. They were clinging onto their title.
But the winner from Kroos was simply sublime.
Sweden felt hard done by in the first half after Marcus Berg was pushed in the back by Boateng in the penalty area
Berg goes down following the pressure of Boateng as Germany goalkeeper Neuer comes out to close him down
Bayern’s Muller has his shirt grabbed in the penalty area by Albin Ekdal in the early stages of the fixture
Draxler had a brilliant opportunity to put Germany ahead in the opening few minutes against Sweden
However, Sweden midfielder Larsson brilliantly blocked Draxler’s close-range effort near the goalline
Germany fans wave their flags prior to the enthralling World Cup clash in Sochi on the weekend
Sweden supporters show off their colours before kick off at the Fisht Olympic Stadium on Saturday evening