Performers create the Olympic rings during the closing ceremony of the 2014 Winter Olympics in Sochi, Russia. Photograph: Ivan Sekretarev/AP

His ice hockey team failed to follow the script. But just about everything else went to plan for a watching Vladimir Putin as Russia celebrated a rush of medals in Sochi with a triumphant closing ceremony on the shores of the Black Sea.

But by the closing ceremony – which featured ballet from the Bolshoi, music by Rachmaninov and tributes to Tolstoy and Kandinsky plus the usual protocol – the atmosphere was one of pure celebration swathed in the colours of the Russian flag. International Olympic Committee president, Thomas Bach, declared the most expensive Games in history "a real special experience". He also personally thanked Putin for his contribution to the "extraordinary success of these Winter Games".

The organisers could even afford to laugh at themselves. The early part of the ceremony featured a knowing nod to the failed snowflake, with a shimmering shoal of dancers making up four of the five rings, before belatedly forming the fifth.

The opening ceremony had been a pleasingly offbeat romp through Russian art and culture. With its marching bands and 1,000-strong children's choir singing the national anthem, this was more of a traditional show of strength.

For the Russians who wildly cheered a clean sweep of the podium in the 50km cross country skiing and a second gold in the bobsleigh for Alexander Zubkov on the final day of competition, a surge of sporting success helped it go with a swing.

Fireworks explode around the Fisht stadium at the end of the ceremony. Photograph: Jonathan Nackstrand/AFP/Getty Images

But Russia, who finished an abject 11th in the medal table in Vancouver four years ago, have poured tens of billions of roubles into ensuring they weren't humiliated at their own party.

As in London, a raft of medals for hometown favourites, a tribe of 25,000 helpful volunteers and a well-judged but extensive security operation buoyed the mood.

"The success of the home team is always an important part of the success of the Games overall. This we saw just two years ago with Team GB in London," said Bach.

The Russian deputy prime minister had earlier said the huge price tag had been worth it and claimed that the Games had helped rebrand his country in the eyes of the world.

"The friendly faces, the warm Sochi sun and the glare of the Olympic gold have broken the ice of scepticism towards the new Russia," insisted Dmitry Kozak. "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."

When the Russian team paraded into the stadium to huge cheers and chants of "Russ-ee-aa", even Putin allowed himself a thin smile.

Actors dressed in Cossacks' attire. Photograph: Action Press/REX

They also had a little help from overseas. The Korean-born speed skater Viktor Ahn, who switched nationality in 2011, won three golds and US-born snowboarder Vic Wild, who acquired Russian citizenship through marriage in 2012, won two.

Not that anyone in the packed Fisht Stadium seemed to care, after the hosts finished the Games with a total of 33 medals, 13 of them gold.

Billy Morgan, a snowboarder and former acrobat who is one of a clutch of "fridge kids" who have captured the imagination at these Games, flipped his way into the arena in his Team GB tracksuit.

The build-up had been beset by a cocktail of security fears, human rights concerns and unease about the huge cost. They did not go away entirely. Images of Pussy Riot being whipped by Cossack guards while performing a song called Putin Will Teach You How to Love the Motherland in front of the Olympic logo will linger. On the penultimate day, a coalition of 33 human rights groups wrote to the IOC calling on it to demand higher standards of its host cities. But the predicted podium protests failed to materialise and Bach insisted on the closing day that athletes had not been leaned on.

IOC president Thomas Bach and Russian president Vladimir Putin at the closing ceremony. Photograph: Darron Cummings/AP

"The Games are not about political disagreements. They are not about political confrontation," said the German, overseeing his first Games as president.

As three giant animatronic mascots and a cast of hundreds of children extinguished the Olympic flame, amid the traditional fireworks, the debate over whether the Games have been worth the huge investment required to build a new city from scratch was only just beginning.

The Russians say they have uses for each of the glittering sports palaces built by the Black Sea and hope Sochi, with its new mountain resort and port, will become a destination for tourists and conferences in summer and winter.