Although Portugal were deemed favorites to emerge winners from the game, it was Germany who had the upper hand.
Germany's compact midfield helped them lessen the impact of Portugal's talented players.
Germany went two up through Bastian Schweinsteiger and Miroslav Klose before Nuno Gomes pulled one back for Portugal shortly before the interval.
Michael Ballack restored Germany's two-goal cushion before substitute Helder Postiga narrowed the gap once again. Germany held onto their lead to go through.
The three-time European champions will face the winners of Friday's quarter-final between Croatia and Turkey.
Germany's Lead
Joao Moutinho should have put Portugal in front after 20 minutes when he was found unmarked by Bosingwa's cross from the right.
But the Sporting Lisbon man somehow missed from four yards after the ball hit his thigh to fly high over.
Portugal were made to pay for the wasted opportunity two minutes later when Schweinsteiger put Germany ahead.
Michael Ballack's neat pass released Lukas Podolski down the left flank.
The Bayern Munich man provided a low cross to club teammate Schweinsteiger, who shrugged off Paulo Ferreira's tame challenge to fire home from close range.
Klose doubled Germany's advantage in the 26th minute when he rose unmarked to head Schweinsteiger's in-swinging free kick past Portugal keeper Ricardo.
Portugal grabbed a lifeline after Gomes scored his first goal in the tournament five minutes before the break.
A swift counter attack saw Simao release Cristiano Ronaldo in the left hand side of the penalty area.
Ronaldo had his shot blocked by Ricardo but Gomes pounced on the rebound to slot into the net despite Christoph Metzelder's desperate attempt to clear the ball away.
Portugal defenders' poor marking in set-pieces and Ricardo's mis-timed jumps came to haunt them once again in the 61st minute.
Ballack rose above Ricardo to head home another pinpoint free-kick from Schweinsteiger.
Postiga narrowed the gap three minutes from time when he towered in between two defenders to power a header past Jens Lehmann.
But his effort proved just a consolation as Germany held on to claim a remarkable win.