KRASNAYA POLYANA, Russia — Alexander Legkov made sure the Russian flag finally flew highest at the Sochi cross-country skiing venue — and for these entire Olympic Games.
On the Games’ last day, Legkov led a Russian medal sweep in the men’s 50-kilometer race to give the host nation its first cross-country gold at the Sochi Olympics. It also clinched the top spot in the overall medals table for Russia, giving it 12 golds and 32 medals overall at that point.
‘‘To win a gold medal on the final day, and win the medals table for Russia, I couldn’t be happier,’’ Legkov said.
Legkov won a four-way sprint to the finish at the end of the freestyle mass-start race Sunday, pulling away from teammates Maxim Vylegzhanin and Ilia Chernousov on the final straight. On a perfect final day for the hosts, Vylegzhanin was second after beating Chernousov in a photo finish, 0.7 seconds behind Legkov.
Martin Johnsrud Sundby of Norway was the only competitor who could keep up with the Russians toward the end but was passed by Chernousov on the final straight and finished fourth, one second behind the winning time of 1 hour, 46 minutes, 55.2 seconds. That left Norway with 11 golds for the Sochi Games.
‘‘This is priceless,’’ said Legkov. ‘‘It’s more valuable than my life, I can’t express how I feel. For 15 years I've been trying for this result.’’
Russia had fallen short of expectations in the cross-country competition until the final race, with only two silver medals from the men’s relay and team sprint events.
But like the country’s biathlon team — which won the concluding men’s relay for its first gold on Saturday — the Russians got it together in the last event.
‘‘We were ready to fight and ready to win,’’ said Vylegzhanin, who earned his third silver medal of the Games. ‘‘We are really glad to get the three top spots in our home Olympics race. It was a really big celebration because we wanted to win for our supporters, for our whole country.’’
Legkov demonstrated his form in the men’s relay last weekend, when he set the fastest time of all skiers on the third leg and helped Russia to get the silver.
And after most of the leading contenders stuck together for 48 kilometers on Sunday, Legkov upped the tempo and created the four-man breakaway group. Legkov led coming into the stadium and stayed in front.
Yelena Valbe, the former Olympic champion who is now head of the Russian ski federation, said the medal sweep in the last event was beyond the team’s expectations.
‘‘Yesterday lots of people said we will have the podium but I was thinking that it was a joke,’’ Valbe said. ‘‘Still, I was believing in the guys and they have proved they are good enough to win.’’
It was the second straight podium sweep in cross-country, after Norway finished 1-2-3 in the women’s 30K race on Saturday.
Aside from Sundby, the overall World Cup leader, none of the other pre-race favorites could match the Russians’ speed toward the end. Johan Olsson of Sweden, the 50K world champion, was 32.1 seconds back in ninth place, while defending Olympic champion Petter Northug of Norway came 18th, 44.5 seconds back.
The race capped a miserable Olympics for Northug, who leaves Sochi without a medal after earning four in 2010, including two golds.
Dario Cologna’s chances for a third gold in Sochi ended when his left ski broke shortly after the 45K mark. The Swiss skier finished 27th.
Noah Hoffman of Aspen, Colo., was the top American finisher in 26th (1:48:04.3).