© Getty Images
Germany went ahead in the 18th minute when Thomas Muller picked up the ball and drove towards goal before firing in a low shot from 20 yards which took a wicked deflection off Russell Martin before nestling in the far corner.
However, Scotland were afforded their own stroke of luck as they drew level in the 28th minute when Shaun Maloney's free kick was spilled by Manuel Neuer and ricocheted into the net off the stationary Mats Hummels.
They were level for little more than five minutes though, as Muller netted his second of the game in the 34th minute. David Marshall repelled Emre Can's initial strike, but the ball fell to Muller, who adjusted well to nod it into the net via the inside of the post.
Mario Gotze then had the ball in the net after a swivel and volley, but the goal was disallowed for offside.
Just two minutes before the break, James McArthur brought another roar from the crowd as he levelled with a controlled half-volley from the edge of the box after Germany failed to sufficiently clear a corner.
© Getty Images
Shortly after the break, Gotze was denied a goal by the offside flag for a second time, but he didn't have to wait long to celebrate his side going ahead once more.
Gundogan played a one-two with Muller before passing the ball into the back of the net off the foot of Marshall's near post.
With Scotland pushing more men forward in search of an equaliser, they became more open at the back and Gundogan almost put the game beyond any doubt with a thunderous strike from the edge of the box, but Marshall beat it away.
Germany held on to secure all three points, which means that Scotland's only hope of qualification now is through the playoffs.