Schalke midfielder Lewis Holtby had given the Germans a deserved lead in the 73rd minute but Fluminense striker Maicon equalised with two minutes of normal time to play and put Germany to the sword with awinner in the first minute of extra time.
Germany dominated the early possesion with Bayer Leverkusen striker Richard Sukuta-Pasu testing Brazil keeper Rafael twice.
The South Americans pushed themselves back into the game and might have taken a first-half lead had it not been for the heroics of Manchester United youngster Ron-Robert Zieler in the Germany goal.
The second half was more one-way traffic as the German midfield pressed hard into the Brazil half.
Time and time again Rafael was equal to the German efforts and it looked like the Brazilian defence were destined to hold out.
But on 73 minutes Germany finally cracked the stubborn back line as Holtby found space and converted after a well-struck corner,his second goal of the tournament.
Brazil coach Rogerio immediately responded by bringing on Maicon for Corinthians midfielder Boquita in what seemed to be a desperate ploy to get men in the box.
Asit looked like Germany were heading for the semi-finals, Maicon struck back, finding the net with just two minutes of normal time remaining.
The extra-time momentum had swung Brazil’s wayand they immediately took advantage as Maicon stepped up to bag his second of the game in the 91st minute.
A tired-looking German side gave it their all but never looked like equalising as Brazil joined Ghana and Hungary in the semi-finals, where they await either United Arab Emirates or Costa Rica.