Opposition candidate Ibrahim Mohamed Solih has won the Maldives' presidential election in a surprise defeat of President Abdulla Yameen.
He took 134,616 votes to beat Mr Yameen, who received 96,132, provisional results showed.
Mr Yameen, who has been accused of crushing dissent in the archipelago, admitted defeat, saying he accepted the result.
The Maldives is a key battleground in the rivalry between China and India.
The US and India have welcomed Mr Solih's win. Mr Yameen had drawn the Maldives closer to China, which has stepped up its presence in the Indian Ocean in recent years.
Many opposition politicians in the Maldives have been jailed under Mr Yameen, and the US and European Union had threatened sanctions before the vote if the democratic situation did not improve.
Supporters of Mr Solih took to the streets in celebration overnight.
"The message is loud and clear. The people of Maldives want change, peace and justice," Mr Solih, widely known as Ibu, told reporters in the capital, Male.
In a televised address to the nation on Monday, after hours of silence, Mr Yameen said he had congratulated Mr Solih, while defending his record.
"The Maldivian people have decided what they want. I have accepted the results," he said.
President Yameen had been widely expected to win another term in office and some observers had believed the election was rigged in his favour. Voter turnout was 89%.
Who is Ibrahim Mohamed Solih?
- One of the most senior politicians in the Maldives, and has for years been calling for democratic reform.
- Joint presidential candidate for an opposition alliance - which includes the Maldivian Democratic Party (MDP), the Jumhooree Party and the Adhaalath Party.
- Mr Solih has been parliamentary leader of the MDP since 2011.
Outside the main opposition campaign centre in Male, hundreds of people gathered overnight to celebrate, chanting "Ibu, Ibu, Ibu".
Exiled former president Mohamed Nasheed, who was ousted by Mr Yameen in 2012, said on Twitter that Mr Solih had done "an extremely good service" to the people of Maldives.
Congratulations to President Elect @ibusolih. You have done an extremely good service to not only to the people of Maldives, but also to freedom loving people everywhere. Democracy is a historical inevitability.— Mohamed Nasheed (@MohamedNasheed) September 23, 2018
What's the situation in the Maldives?
The Maldives is made up of 26 coral atolls and 1,192 islands. More than 400,000 people live there but its future hangs in the balance due to climate change. Tourism is a vital part of its economy.
The archipelago has been gripped by political upheaval in recent years. In February the Supreme Court quashed the convictions of nine opposition figures, among them Mr Nasheed.
But after President Yameen declared a state of emergency and ordered the arrest of two judges, the court reversed its decision.
The move was seen as a sign that Mr Yameen would not tolerate any challenge to his rule and sparked criticism from Washington, London and Delhi.
Some in India, meanwhile, called for an intervention in a small, neighbouring country once seen as firmly within its sphere of influence. Mr Nasheed also appealed for Indian military intervention.
In a statement after Mr Solih's victory, India's Ministry of External Affairs said Sunday's election marked "not only the triumph of democratic forces in the Maldives but also reflects the firm commitment to the values of democracy and the rule of law".
Has the Maldives come full circle?
Analysis by Olivia Lang, BBC News
Any fears that Abdulla Yameen would attempt to cling onto power have now been allayed.
In his address to the nation, Mr Yameen said he had had a "difficult" time in office, but had always worked to uphold the rule of law.
Almost a decade on from when the country's first ever democratic election ended 30 years of rule under Maumoon Abdul Gayoom (Mr Yameen's half-brother), many Maldivians feel they have ousted another strongman at the ballot box.
But the road ahead is not so simple. Many of the challenges the country faced in 2008 remain, including widespread corruption and a weakened judiciary. Judges and MPs are in jail. The free media has been battered. And new challenges, such as Islamist extremism, will not be easy to fix.
The current opposition alliance is a mixed bunch, brought together only by their mutual desire to bring down Mr Yameen. Not all have the same democratic tendencies. Mr Solih now faces the unenviable task of trying to unite the various forces and bring the country back to the democratic path from which many believe it has strayed.
What role has China played in the Maldives?
As part of Beijing's push to gain strategic influence and carve out new trading routes in the Indian Ocean and beyond, it has lent billions for huge infrastructure projects in Pakistan and Sri Lanka, and operates key ports in those countries, to the chagrin of India.
Under Mr Yameen, the Maldives has also welcomed Chinese money for major projects and signed a free trade agreement. More tourists from China now visit the Maldives than from any other country.
Before the vote, analysts said that Beijing feared any change in government that could affect its interests. India, meanwhile, was seen as preferring the opposition, because of its concerns about Mr Yameen's cosy ties with its regional rival.
Was it a fair election?
Some international monitors, including from the EU and UN, did not send teams to monitor the election, fearing their presence would appear to condone Mr Yameen's re-election. Others said they could not get visas in time.
On Saturday, police officers searched the opposition Maldivian Democratic Party office in Male without a warrant, the party said.
Before announcing provisional results, the election commission's chief, Ahmed Shareef, said there were no irregularities that could affect the outcome of the vote, the Maldives Independent newspaper reports.
Mr Yameen has shrugged off accusations of authoritarianism, saying during the campaign: "No-one will come to greet me and shake my hand, if there is tyranny."