Fabio Capello's men began the day three points clear of second-placed Portugal and needing a draw in Baku to ensure they would be on the plane to Brazil.
Roman Shirokov set Russia on their way after 16 minutes and a win looked even more likely when Maksim Medvedev was sent off for the home side after 73 minutes.
But Vagif Javadov's last-minute strike set nerves fluttering, although the visitors held on for the result they needed.
Russia finish the group one point ahead of Portugal, who were comfortable 3-0 winners over Luxembourg but still have to settle for a play-off spot.
The 29th-minute dismissal of Aurelien Joachim left the visitors with a mountain to climb and they could not keep out goals from Silvestre Varela (30), Nani (36) and Helder Postiga (78).
The other match in the group between Israel and Northern Ireland ended in a 1-1 draw, with Eden Ben Basat giving the home side a 44th-minute lead before Steven Davis' reply (73).
Bosnia-Herzegovina will head to the World Cup finals for the first time in their history thanks to a 1-0 win over Lithuania.
Vedad Ibisevic scored the only goal after 68 minutes to ensure the Balkans would top Group G ahead of Greece, whose 2-0 victory at home to Liechtenstein was not enough.
Dimitris Salpingidis (seven) and Giorgos Karagounis (81) were the scorers for the Greeks, who now face a play-off if they want to make it to Brazil next summer.