Algeria were impressive in the first half, pressing Germany well and playing on the break, but they were reliant on Rais M'bolhi in goal on a number of occasions in the second half.
It went to extra time, and it was substitute Andre Schurrle who flicked in the first with his heel in the first period before Mesut Ozil made the result certain late on. There was still time for a late consolation from Abdelmoumene Djabou.
Here, Sports Mole takes a closer look at the action to analyse the result.
On target: 9
On target: 6
Was the result fair?
In the end, yes. Algeria showed fantastic fighting spirit and a very stern defence, but in the end the better quality of Germany shone through. It took more than 90 minutes to separate the teams, however, and the Germans will need to improve in the next round. Germany had more shots, more possession and more of what mattered, so the result did go the right way even if Algeria will feel hard done by.
For a team so full of attacking talent, Germany seemed short of ideas in the final third for big spells of the game. In the first half they mainly resorted to shots from range, but they gradually got on top of the game as Algeria's defending got more last-ditch. They were in control in extra time and, after the early goal, the result was only going one way. Improvement is necessary against France.
They were brave and organised and they pressed Germany very well throughout, but they just did not have that touch of quality to convert chances on one of their many breaks. The defence, in particular Rafik Halliche, held up strongly for most of the game, but it was just too much for them to manage it for another 30 minutes. They cannot really have any complaints with the score, but will go home with plenty of pride.
Sports Mole's man of the match
Rais M'Bolhi: If not for the Algeria goalkeeper, the result would have been secure long before it was. He produced a string of saves, most notably a double attempt in the first half to deny first Toni Kroos and then Mario Gotze. His handling was also very secure and he hardly deserved to end on the losing side. Had Algeria got through, they would have had M'Bolhi to thank.
Manuel Neuer had a very good game playing almost as a sweeper, but he very nearly cost his side the opening goal in the first half. He came for the ball, but missed out to Islam Slimani and was forced to recover with a sliding tackle. He was excellent after that, but his mistake could have been crucial.
Sandro Ricci had a very good game. He did not reach for his pocket for a few early mistimed tackles, but did do when necessary as the game went on. There were no controversial decisions to make, but he dealt with everything well overall.
Germany: Joachim Low's side move into the quarter-finals to take on France, who beat Nigeria earlier in the day. They will need to improve to beat the French in what will be a clash of two European giants.
Algeria: Algeria go home, but they have not been disgraced at all. The pressing style of football they played throughout will be a lasting memory of their best World Cup performance.