LONDON — Fireworks and celebratory gunfire rang out in Tunisia and Lebanon, South Africans recalled Nelson Mandela's euphoric release from prison, and two words — "Congrats Egypt" — dominated social media sites as the world cheered the ouster of Egypt's Hosni Mubarak.

U.S. and European officials on Friday saluted the resilience of the demonstrators in Cairo — who mobbed the capital for 18 days to demand their rights, despite attacks from pro-government thugs — and pledged assistance to help Egypt make the transition to democracy.

"In their eyes, you can see what power freedom can have," German Chancellor Angela Merkel said of the protesters, adding that, by stepping down, Mubarak had rendered "a last service to the Egyptian people." Merkel herself had lived under another autocratic regime, growing up behind the Iron Curtain in East Germany.

President Barack Obama — whose administration has walked a fine line between backing the protesters' demands and supporting Mubarak, a long-term U.S. ally — welcomed the wave of peaceful change washing across the country.

"The people of Egypt have spoken. Their voices have been heard. And Egypt will never be the same," he declared. And while he noted that many important questions remain unresolved, Obama said: "I'm confident the people of Egypt can find the answers."

But mixed with the messages of hope was concern for the future of a critical partner in the Middle East peace process, lingering fear of violent unrest — and guilt over the close partnership that many Western countries shared with Mubarak's regime.

"Mubarak's tyranny was typical across the region, and it is Europe's shame that we sustained them," said Edward McMillan-Scott, the European Parliament's vice president for democracy and human rights.

Merkel expressed hope that whoever comes to power works to "uphold peace in the Middle East and respect the treaties concluded with Israel," while French President Nicolas Sarkozy said reforms are needed quickly so Egypt "can keep its place in the world at the service of peace."

Portuguese Foreign Minister Luis Amado warned that "we will face a very dangerous situation" if the transition isn't completed soon. Peru's foreign minister said he feared a rise in the price of oil amid continued instability.

Whatever the uncertainty, euphoria ruled the streets. In Tunisia, whose people-powered revolution pushed dictator Zine El Abidine Ben Ali into exile just last month and sparked the Egyptian protests, cries of joy and a thunderous honking of horns greeted the news.

In Beirut, fireworks and celebratory gunfire erupted over the capital only moments after Egyptian Vice President Omar Suleiman said Mubarak had handed power over to the military. In the West African nation of Mauritania, pedestrians and cars filled Nouakchott, the capital, to celebrate. Across the world, Egyptian expatriates celebrated in boisterous rallies at their country's embassies and consulates.

In South Africa, officials noted that Mubarak's resignation took place exactly 21 years to the day after Mandela's historic release from prison.

"One can't escape the symbolic importance of this day and the release of Mandela and how that ushered in a new process for South Africa," said Ayanda Ntsaluba, director general of South Africa's foreign affairs department. "Let's hope this happy coincidence will also one day make the Egyptian people look back and say this indeed was the beginning of better times in Egypt."

Tunisia's caretaker government, put in place after the nation's leader fled the country, praised the Egyptian people for forcing Mubarak out of office and expressed hope that it will lead to the "triumph of Arab causes."

Some European and U.S. officials have expressed concern that instability in Egypt could throw the peace process between Israelis and Palestinians into chaos — and provide an opening for Islamist forces such as Egypt's Muslim Brotherhood. Many are also worried that the military takeover may not necessarily spell an end to the rights abuses perpetuated during Mubarak's nearly three decades in power.

Foreign Minister Radek Sikorski of Poland, whose own nation threw off repressive communist rule 21 years ago, said the changes sweeping Egypt "create both hope and anxiety." Amnesty International's Secretary General Salil Shetty agreed, saying that Mubarak's departure "is not the end."

"The repressive system that Egyptians have suffered under for three decades has not gone away and the state of emergency remains in place," he said.

U.N. Secretary-General Ban Ki-moon called for the "early establishment of civilian rule," a sentiment that was shared across Europe, whose leaders had increasingly pushed Mubarak to open up Egyptian society and worked quickly to shake off any links to the deposed leader.

Sarkozy described Mubarak's resignation as "necessary," while Swiss officials froze assets belonging to Mubarak and his family.

An unusual joint statement from EU president Herman Van Rompuy, foreign policy chief Catherine Ashton and Jose Manuel Barroso, head of the executive European Commission, said the EU "salutes the courage of the Egyptian people" and called for the formation of a civilian government, while Britain's foreign minister warned Egypt's newly installed military authorities against backsliding.

In a Twitter message, Turkish Foreign Minister Ahmet Davutoglu said: "Congratulations to the Egyptian people." A flood of support poured onto the micro-blogging site, where the words "Congrats Egypt" were among its most popular terms.

Even Iran, which had crushed its own pro-democracy protests in 2009, praised the uprising, which it claimed would doom Israel and give Washington a black eye. The U.S. condemned that statement as hypocritical.

While many Latin American countries expressed support for the resignation — Ecuador's vice foreign minister called it "not only a joy for the Egyptian people but a joy for the world" — Venezuela condemned what it saw as U.S. interference.

"Nobody should meddle in the domestic affairs of Egypt's people," Venezuela's Foreign Minister Nicolas Maduro said. "It's truly appalling ... how Washington is attempting to watch over (and) hold sway over a strong country like Egypt with statements from President Obama, the State Department, the head of the CIA."

There were guarded comments from other authoritarian governments, with Russia's foreign minister saying the developments showed "authorities have approached the problem responsibly" and calling for a rapid return to stability. The United Arab Emirates said it had confidence in the armed forces' ability to manage Egypt's affairs "in these delicate circumstances."

Mubarak's departure also came 32 years to the day after the collapse of the shah's government in Iran — and one European academic said Mideast governments should not ignore Friday's seismic shift in the old world order.

"This is the popular demonstration that proves any leader can be toppled," said Eugene Rogan, the director of the Middle East Center at St. Antony's College in Oxford. "For all the other rulers in the region, it's a very sobering moment."

In South Africa, U2 rehearsed Friday at the country's historic FNB Stadium — known as Soccer City when it hosted the World Cup last year.

"This continent is on fire," marveled lead singer Bono.

Associated Press journalists around the world contributed to this story.