Both nations will progress with victories in their final group games, but equally – and however unlikely - both sides would also be eliminated should Japan beat Spain and Costa Rica beat Germany.
Spain, featuring City’s Aymeric Laporte and Rodrigo, looked set for a place in the Round of 16 for much of the game.
In a cagey game of few opportunities, Germany looked to have struck first when Antonio Rudiger powered a first-half header home, only to see his effort ruled out for offside.
City team-mates Laporte and Rodrigo played in Spain’s central defence and looked calm and collected throughout and very comfortable with their tactic of playing from the back.
Gundogan found it difficult to get the space needed to cause the Spanish any real concern but was tidy and inventive whenever he did have the ball.
But the deadlock was finally broken on 62 minutes when Alvaro Morata put Spain ahead when he nipped in to turn Jordi Alba’s low cross past Manuel Neuer.
A frustrated Gundogan was substituted on 70 minutes and replaced by former City team-mate Leroy Sane, as Germany boss Hansi Flick chased an equaliser.
And his changes paid off when Niclas Fullkrug thumped home a leveller on 83 minutes.
Sane had a chance to win it deep into added time, but after taking the ball around the keeper, he saw his cross cleared.
Spain now need just a point to guarantee qualification, while Germany know that victory over Cost Rica and a Spanish win over Japan will book thein spot in the last 16.
Afterwards, Gundogan said: “We needed that - we could have scored earlier, but we had a couple of really good chances as well.
“The result is good against a very tough Spain side
“Playing at the World Cup, there will be dramatic moments in some games and I was sat on the bench with Thomas Muller and we felt there was a goal still in it for us.”