Germany endured a tense finale in Basel but eventually came out as winners of the first quarter-final of Euro 2008, beating tournament high-flyers Portugal 3-2 in Basel with goals from Schweinsteiger, Klose and Ballack.
Germany were dominant for large portions of the game but still had to fight for the victory
Two early goals from Bastian Schweinsteiger and Miroslav Klose laid the foundations for the victory and although Nuno Gomes pulled one back for Portugal, captain Michael Ballack's header on 61 minutes restored Germany's two-goal cushion. Substitute Helder Postiga reduced the deficit once more on 87 minutes but Germany held on.
Germany, who beat Portugal by 3-1 in the third-place playoff at the 2006 World Cup, now meet either Croatia or Turkey on June 25 for a place in the final.
Joachim Loew's side started the stronger on a relaid pitch at St Jakob Park, with Thomas Hitzlsperger twice trying his luck from distance before Portugal slowly started to find their feet.
First Cristiano Ronaldo almost broke clear in the area before Joao Moutinho steered a Bosingwa cross from the right just over Lehmann's goal.
Rapid double rocks Portugal
But just as Portugal appeared to be getting on top, Germany scored twice in the space of four minutes to stun Luiz Felipe Scolari's side.
Schweinsteiger slid home the first on 22 minutes, meeting a Lukas Podolski cross from the left at the near post after his Bayern Munich team-mate had played a swift 1-2 with Michael Ballack.
Schweinsteiger was a different player to the one sent off against Croatia
Schweinsteiger - unrecognizable from the player sent off against Croatia for pushing an opponent - turned provider on 26 minutes, floating in a free-kick which Miroslav Klose headed past Ricardo to make it 2-0.
Despite the two-goal deficit, Portuguese heads didn't drop and Per Mertesacker had to be alert to cut out a dangerous Ronaldo cross after 33 minutes while Raul Meireles, who came on for the injured Joao Moutinho, blasted over when the Porto midfielder should have done better.
Gomes follows up to drag Portugal back into game
Portugal's renewed dominance eventually paid dividends five minutes before the break when Lehmann could only parry a goal-bound Ronaldo shot into the path of Nuno Gomes, whose low shot found the bottom-right-hand corner via Mertesacker's outstretched right boot.
Ballack had a good game and capped it with a goal
The second half began as the first one ended, albeit in heavy rain, with Portugal in total control and Germany apparently happy to play the risky game of sitting back and soak up the pressure.
But despite all their pressure, a Pepe header from close range, which sailed over, was the closest Portugal came to leveling the match.
Captian Ballack restores two-goal lead
Ballack made the Portuguese pay for their lack of a cutting edge up front just after the hour mark, heading home another Schweinsteiger free kick to make it 3-1.
The goal outraged Scolari in the technical area as the Brazilian complained that the Chelsea star clearly appeared to push his club team-mate Paolo Ferreira before scoring.
Scolari brought on Nani for Gomes and Helder Postiga for Petit in an effort to turn things around and it was Nani who floated in a perfect cross for the unmarked Postiga to make it 3-2 with just three minutes remaining. But it was too little too late for Portugal.