The result will not affect Prime Minister Viktor Orban’s grip on national power as his Cabinet is buoyed by a strong economy, fierce anti-immigration rhetoric and hefty wage rises. His ruling Fidesz party remains wildly popular in rural areas.
No general election is due until 2022 and Orban, who rose to power in 2010, holds a huge majority in parliament.
With 81.6% of votes counted, Karacsony had 50.6% support compared with 44.3% for Tarlos, according to data on the National Election Office website.
The better-than-expected showing for the opposition, including a late surge by the 44-year-old Karacsony, vindicated its strategy to field joint candidates, seen as the best way to challenge Fidesz, which had scored seven consecutive landslide election wins on the national, municipal and European levels since 2010.