Guatemala is the venue for the IOC meeting |
The result was announced by International Olympic Committee President Jacques Rogge after votes at an IOC meeting in Guatemala.
In earlier voting, the third contender, Salzburg in Austria, was eliminated.
The presidents of all three candidate countries had attended the meeting to plead their countries' cases.
Russia's President Vladimir Putin, a keen skier, said that in Sochi 70% of athletes would live within five minutes' walk of the venues, so there would be no traffic problems.
The Black Sea resort has a unique combination of springlike weather and cold temperatures in the nearby Krasnaya Polyana mountains, which President Putin said would guarantee snow.
"Winter sports are popular in Russia and our sportsmen have won many competitions and have made a big contribution to the Olympic movement," he said.
"But we have never won the honour to celebrate the Winter Olympic Games.
"You know we can turn sports competitions into a really spectacular show and we are good at it."
For both Salzburg and Pyeongchang, this was their second consecutive defeat. Both had lost out in the bidding for the 2010 Winter Games, which will be held in the Canadian city of Vancouver.
The 20th Winter Games took place in Turin in Italy in 2006.