Toni Kroos curled home the winner with a final-minute free-kick, after being teed up by Marco Reus to the left of the penalty area.

It came after Marcus Berg had given Sweden a shock lead (32') before Reus drew his side level immediately after half-time (48').

Jerome Boateng was sent off (83) after receiving a second yellow card but the defending champions still found a way to win, when defeat would have left them eliminated.

Germany still need to beat South Korea in their final group game but can be reassured that qualification remains in their own hands.

Manager Joachim Low made four changes to the side which lost to Mexico last time out and his side started brightly, pinning Sweden back straight from the kick-off.

But after weathering an early storm, the Swedes grew confidence and felt they should have won a penalty when Boateng appeared to push Marcus Berg inside the area when the striker was through on goal (13').

They took the lead when Viktor Claesson pounced on a loose pass and crossed for Toivonen's, who chested the ball down before looping it over goalkeeper Manuel Neuer (32').

Germany responded after the break and equalized immediately when Reus stabbed home Timo Werner's cross (48'), which took a deflection before reaching the midfielder.

The defending champions pushed for a winner, as Werner blazed an effort over the bar from inside the penalty area (82').

A minute later they were reduced to ten men when Boateng lunged into a challenge and received a second yellow card (83').

Still Germany piled men forward and almost snatched a winner when substitute Julian Brandt hit the post (92').

Eventually they got their reward when Kroos produced a moment of magic at the death (95').