BEIJING — With help from British star power, China concluded its debut as Olympic host Sunday after 16 days of near-flawless logistics and superlative athletic achievement — coexisting awkwardly with the government’s wariness of dissent and free speech.

A spectacular closing ceremony opened with torrents of fireworks and included a pulsating show-within-a-show by London, host of the 2012 Games. From a stage formed from a red double-decker bus, Led Zeppelin guitarist Jimmy Page played classic rock hit “Whole Lotta Love” and soccer icon David Beckham booted a ball into the surrounding throng of athletes on the stadium floor.

Then more lyrical music returned, and the Olympic flame atop the stadium was extinguished. A carnival-themed segment completed the show, featuring a duet by Spanish tenor Placido Domingo and Chinese soprano Song Zuying. There was another, noisier barrage of fireworks and confetti filled the air.

To a large extent, China, an emergent superpower, got what it had craved from these long-sought games: a dominant effort by its athletes to top the gold-medal standings for the first time and almost glitch-free organizing that showcased world-class venues and cheerful volunteers to the largest-ever peaceful influx of foreign visitors.

As a bonus, not just one but two athletes gave arguably the greatest performances in Olympic history — Michael Phelps with his eight gold medals in swimming, Jamaica’s ebullient Usain Bolt with three golds and three world records in the sprints.

The International Olympic Committee, whose selection of Beijing as host back in 2001 was widely questioned, insisted its choice had been vindicated.

“Tonight, we come to the end of 16 glorious days which we will cherish forever,” IOC President Jacques Rogge told the capacity crowd of 91,000 at the National Outdoor Stadium, and a global TV audience. “Through these Games, the world learned more about China, and China learned more about the world.”

“These were truly exceptional games,” he said, before declaring them formally closed.

Memorable momentsThe head of the Beijing organzing committee, Liu Qi, said the games were “testimony to the fact that the world has rested its trust in China.” He called them “a grand celebration of sport, of peace and friendship.”

Rogge and the IOC were criticized by human rights groups for their reluctance to publicly challenge the Chinese as various controversies arose over press freedom and detention of dissidents. Athletes shied away from making political statements, and “protest zones” established in Beijing went unused as the authorities refused to issue permits for them.

But the atmosphere was festive at the stadium as fireworks burst from its top rim — and from locations across Beijing — to begin the closing ceremony.

After an army band played the Chinese national anthem, hundreds of gayly dressed dancers, acrobats and drummers swirled onto the field, then made room for the athletes, strolling in casually and exuberantly from four different entrances.

China invested more than $40 billion in the games, which it viewed as a chance to show the world its dramatic economic progress. Olympic telecasts achieved record ratings in China and the United States, and the games’ presence online was by far the most extensive ever.

Rogge said these Olympics would leave a lasting, positive legacy for China — improved transportation infrastructure, more grass-roots interest in recreational sports, a more aggressive approach to curbing air pollution and other environmental problems. Smog that enveloped the city early in the games gave way to mostly clear skies, easing fears that some endurance events might be hazardous for the athletes.

American rower Jennifer Kaido of West Leyden, N.Y., said the games exceeded her expectations.

“We were prepared for smog, pollution, demonstrations, but everything has gone very smoothly,” she said.

Rogge acknowledged that China, despite promises of press freedom during the games, continued to block access to numerous politically oriented Web sites, including those related to Tibet and the outlawed spiritual movement Falun Gong.

However, he contended that media restrictions were looser during the Olympics than beforehand, “and so we believe the games had a good influence.”

Human rights groups disagreed.

“The reality is that the Chinese government’s hosting of the games has been a catalyst for abuses, leading to massive forced evictions, a surge in the arrest, detention and harassment of critics, repeated violations of media freedom, and increased political repression,” said Sophie Richardson of Human Rights Watch. “Not a single world leader who attended the games or members of the IOC seized the opportunity to challenge the Chinese government’s behavior in any meaningful way.”

Led by Phelps and Bolt, athletes broke 43 world records and 132 Olympic records during the games. Yet Rogge, who visited every venue, said the most touching moment for him came after the 10-meter air pistol event, when gold medalist Nino Salukvadze of Georgia embraced runner-up Natalia Paderina of Russia even as their two countries’ armies fought back in Georgia.