Budapest election: Hungary's Orban in shock defeat
Hungary's opposition has won the mayoral election in Budapest, ousting the ruling party incumbent.
Liberal challenger Gergely Karacsony defeated Istvan Tarlos, backed by Prime Minister Viktor Orban's right-wing Fidesz party.
The shock win represents the first major electoral blow to Mr Orban since he swept to power in 2010.
The opposition also made gains nationwide, winning in 10 out of 23 major cities voting.
In Budapest, opposition candidates won district mayoral posts as well, giving them a majority on the city council.
- The Rise of the Right: Populism in Hungary
- The man who thinks Europe has been invaded
- Hungary faces unprecedented EU action
Centre-left and pro-European Mr Karacsony called his win "historic".
"We will take the city from the 20th Century to the 21st," he said. "Budapest will be green and free, we will bring it back to Europe."
By Nick Thorpe, BBC News, Budapest
This was the first major defeat for Fidesz in an election since 2006. Viktor Orban tried to console supporters on Sunday night. "Fidesz is the biggest party in Hungary, and we will act according to that knowledge," he said.
A sex scandal in the western city of Gyor, in which videos surfaced of the married Fidesz mayor, Zsolt Borkai apparently participating in an orgy on a yacht in the Adriatic, appears to have damaged Fidesz in urban centres where independent media are still widely available.
A year ago, opposition parties tried and failed to organise an anti-Fidesz alliance in parliamentary elections. In this municipal election, agreements were struck in three-quarters of the country, and even where Fidesz candidates won, the opposition often increased their share of the vote.
In Budapest, Gergely Karacsony did not simply win the post of mayor, but 14 of the 23 district mayors went to opposition candidates, and they will have a clear majority on the city council.
The challenge for Fidesz will be to remobilise their own passive supporters, and for the opposition, to build an infrastructure in the countryside, where Fidesz still enjoy the strongest support.
Leading up to the election, Fidesz tried to cast Mr Karacsony negatively as pro-immigration and unsuitable for office. Mr Orban threatened to withhold co-operation from municipalities that did not elect his party's candidate.
The favourite in the mayoral race, Mr Tarlos, may have been damaged by the sex scandal involving a Fidesz mayor that emerged last week.
Since taking office, nationalist Mr Orban has clashed with Brussels over migration and rule-of-law concerns. He has reformed Hungary's institutions, concentrating power and media organs in his hands.
The elections were seen as a chance to wrest power from Mr Orban and Fidesz, which holds a large majority in parliament.
Opposition parties came together to back Mr Karacsony and put up just one united opposition challenger in many municipalities.
Two provincial cities, Dunaujvaros and Eger, were won by Jobbik, the former far-right party, with the help of Socialist, Liberal and Green voters. Jobbik voters elsewhere backed left-wing and liberal candidates.