The cheering began even before the athletes appeared. The 40,000 spectators at the Closing Ceremony of the Sochi Olympics knew three Russians would be striding out to the victory podium Sunday at Fisht Stadium, three instant national celebrities whose sweep of the men’s 50-kilometer cross-country ski race had lifted their nation to the top of the medal standings.

As Alexander Legkov received Russia’s 13th gold medal of the Winter Games, thousands of his countrymen stood, sang their anthem and bellowed one last chant of “Rossiya!’’ Their fervor was aimed at their athletes, but it reflected a broader national pride as well. For the past seven years, while Russia prepared for its turn on the global stage, the world wondered whether a faded resort town on the Black Sea could pull off a successful Winter Games.

Those doubts grew louder as the Olympics approached. But Russia proved it was up to the challenge, and it was showered with applause before and during Sunday’s grand finale.

International Olympic Committee President Thomas Bach, presiding over the first Games since his election, thanked Russia for delivering on its promises. U.S. Olympic Committee executive Scott Blackmun praised the Sochi Games as one of the best-organized, most smoothly functioning Olympics he had seen.

Despite ongoing concerns about human-rights abuses, corruption and other issues, Sochi staged a secure, festive and efficiently run Winter Games, one that Deputy Prime Minister Dmitry Kozak said had “broken the ice of skepticism toward the new Russia.’’

“The Games have turned our country, its culture and the people into something that is a lot closer and more appealing and understandable for the rest of the world,’’ Kozak said in a news conference Saturday. “The commitments we took on [to host the Olympics] seemed fantastical and impossible to fulfill.

“Today, you can see for yourselves that Russia can keep its word. Russia managed to prove to itself and the rest of the world that we are capable of making the impossible possible.’’

Russia demonstrated renewed might in the Olympic sports arena, winning 33 medals and becoming only the fourth host nation to lead the medal standings. The U.S. finished second in the total medal count with 28 and won nine golds, fourth behind Russia, Norway and Canada.

Kozak and Dmitry Chernyshenko, president of the Sochi 2014 organizing committee, both spoke frequently of Russia’s opportunity to cast off old stereotypes during its two weeks in the spotlight. In a Closing Ceremony that celebrated Russia’s cultural and artistic heritage, a country typically viewed as dour and humorless showed it can even laugh at itself. The show’s opening segment featured dancers forming Olympic rings; in a reference to the much-discussed Opening Ceremony glitch, when one ring failed to unfold, the dancers created only four rings before adding the fifth to wild applause.

In the face of criticism about the $51 billion invested in the Games, officials were quick to point out that most of that was spent on infrastructure. Sochi’s new ski resorts, roads and public transit — all built in the past seven years — impressed visitors and helped Russia dispel its image as a drab, uninviting place.

Kozak said the Olympics changed the country’s psyche, too. The effort required for such a massive undertaking, he explained, instilled a new can-do outlook. He cited a change in attitudes toward people with disabilities, because new structures had to be built to be accessible, and said that volunteer work — virtually unknown in Russia before — has surged in popularity after the recruitment and training of 25,000 volunteers for the Games.

President Vladimir Putin even set aside his stern persona during the Games, greeting athletes at their village and spending 30 minutes mingling with American fans at USA House. Bach lauded him for his “personal commitment to the extraordinary success’’ of the Olympics, but the IOC president also echoed his remarks at the Opening Ceremony when he referred to the Olympic message of “peace, tolerance and respect.’’

There have been concerns that when the world is no longer watching, Russia will revert to some of its old habits. Kozak promised there would be no retribution toward those who protested peacefully at the Games, including the feminist punk rock group Pussy Riot and the Italian transgender activist Vladimir Luxuria.

When the Olympics began, some wondered whether Russians would embrace them with any warmth. That question was answered with lively crowds at Olympic Park and in the venues, and at the Closing Ceremony. When Bach declared the Games closed, an audible sigh arose from the stands.

Saying farewell to an event that had such a profound impact on his country, Kozak said, was a sad moment. Chernyshenko found another adjective to describe it.

“Russia has delivered on its promise,’’ Chernyshenko said. “It is a great moment in our history. This is the new face of Russia. Our Russia.’’