LONDON – Usain Bolt made himself a living legend — just ask him. Michael Phelps swam a last lap into history. A man ran on carbon blades. Two track stars and a long jumper produced perhaps the greatest night in British sports history.

The nightmare that was supposed to be the 2012 Olympics — gridlock and chaos Underground and overground, a city locked down by terrorist threats, day after day of gray and drizzle — simply never materialized. Instead, London had a five-ring party.

“Nobody wanted to sit this dance out,” said Sebastian Coe, the two-time Olympic 1,500-meter track champion and chief of the London organizing committee. “Everybody has wanted to be involved.”

Or, as the stately Economist said: “Britain looked at itself and liked what it saw.”

The games were not without controversy.

Eight badminton players were sent home in disgrace for trying to lose, doing it to gain a better draw in their tournament but violating the Olympic spirit of competition.

Organizers scrambled to sell last-minute tickets and ended up giving some to the military, after unsightly photos of empty seats were splashed across a cantankerous British press.

Some moments were downright ugly. A Greek triple jumper made a racist joke on Twitter. A Swiss soccer player used a slur to describe the South Koreans who had just won, and said they “can go burn.”

At what was called the first social media Olympics, both remarks made it around the world in seconds. The punishment came almost as quickly: Go home.

The athletes who misbehaved were drowned out anyway. Tens of thousands of people flocked daily into Olympic Park. They filled Olympic Stadium for morning heats. They gave the handball arena a new name: The Box That Rocks.

They camped out on the grass to watch on big screens. Flags — the Union Jack most prominently — became shirts and shorts, caps and capes, earrings and nail polish. Fans wore national colors proudly, and literally.

And what a show they saw.

Bolt, the Jamaican track sensation, blew away the field in the 100 meters in 9.63 seconds and the 200 in 19.32, becoming the first athlete to win both sprints at consecutive Olympics.

He was so dominant that sometimes the question wasn’t just whether he would win but whether he would run at full speed to the finish, and what theatrics he would produce to celebrate.

He did pushups on the track. He struck the pose of an ancient, triumphant Olympian, or perhaps a superhero.

“I am now a living legend,” he said. “Bask in my glory.”

Bolt struck a third time Saturday on the next-to-last night of the games, running a blistering anchor leg to set a world record in the 400 relay for his third gold. He was so good that track officials let him keep the baton.

Elsewhere on the track, David Rudisha of Kenya led for the entire race in the 800 meters and broke his own world record. The standout performance of the games, proclaimed no less a track star than Coe himself.

Carmelita Jeter anchored the American 400-meter relay team to a winning time of 40.82 seconds, more than a half-second better than a mark that stood for more than a quarter-century.

The United States used a dominant showing in track and field to blow past China and lock up the races for total medals and golds. Going into the final day, the United States had 44 gold medals, one shy of its record for an Olympics on foreign soil.

In the pool alone, the Americans won 31 medals. And Michael Phelps, in a dazzling farewell, became the most decorated Olympian of all time. He came away with four golds and six overall to eclipse not just his contemporary rival, Ryan Lochte, but Soviet gymnast Larisa Latynina, who held the previous record for most Olympic medals with 18.

Phelps has 18 golds and 22 overall medals for his career.

He left just as another American swimmer, 17-year-old Missy Franklin, was stepping into the spotlight. She captured four golds, equaling the U.S. mark for a female swimmer.

She was only one star at a breakout Olympics for women.

Gabby Douglas, the 16-year-old American gymnast, won two gold medals, including the all-around. Six women’s world records were set in the pool.

Alex Morgan scored a late header that sent the U.S. women’s soccer team to a semifinal victory against Canada and propelled them to an eventual gold. In tennis, Serena Williams won gold in singles, and another in doubles with her sister, Venus.

Women’s boxing made its debut and was a huge hit. Britain’s Nicola Adams, Ireland’s Katie Taylor and U.S. teen Claressa Shields became stars in their gold-medal bouts.

Kerri Walsh Jennings and Misty May-Treanor did what they always do — own the sand. They won their third straight gold in beach volleyball and did it at perhaps the best setting of the games, within a long serve of 10 Downing Street.

Saudi Arabia, Qatar and Brunei sent female Olympians for the first time.

Saudi judo fighter Wojdan Ali Seraj Abdulrahim Shahrkhani lost, in a headscarf and in less than 90 seconds. But she drew an ovation and made a statement just by being here.

So did Oscar Pistorius, the double-amputee from South Africa with carbon-fiber blades. He reached the semifinals in the 400 and ran anchor on a 4×400 relay team that finished last in the final. Nobody minded.

“When I left the stadium I just turned around and looked at the crowd, and it’s something I will definitely remember for the rest of my life,” Pistorius said.

By the tens of thousands, Londoners shared the sentiment. For the host nation, a cast of athletes cemented their place in British lore.

Bradley Wiggins followed up his win in the Tour de France with gold in the time trial and became the most decorated British Olympian. Track cyclist Chris Hoy won his sixth career gold. Ben Ainslie sailed to his fourth.

Andy Murray finally won at Wimbledon, thrashing Roger Federer in straight sets on Centre Court — a month after losing to him in the Wimbledon final.

Britain piled up 28 gold medals and will finish third in the table. Not since another London Games, in 1908, has Britain performed so well.

It peaked on a Saturday night, when Britain won three gold medals in track and field in less than an hour — Jessica Ennis in the heptathlon, Mo Farah in the 10,000 meters and Greg Rutherford in the long jump — to a deafening roar.

The reserved president of the International Olympic Committee, Jacques Rogge, made no secret of his delight.

“For two weeks,” he said, “the Olympic Park has been the beating heart of the world.”

Rogge will deliver his final verdict during Sunday’s closing ceremony, when the Olympic flame will be extinguished and the Olympic flag handed to Brazilian organizers of the 2016 Games in Rio de Janeiro.

Normally reserved Britons embraced, put down their newspapers and spoke to each other on the Tube, and reveled in sports like never before.

“The doom mongers said it couldn’t be done,” said London Mayor Boris Johnson, who was responsible for one of the few mishaps of the games — getting himself stuck on a zip line.

“Well, they were wrong,” he said. “It was done, it was stunning, and it will live long in the memory.”