South Korean voters have overwhelmingly chosen the liberal candidate Moon Jae-in as their next president, an exit poll suggests.
It put Mr Moon on 41.4%, with his nearest challenger, conservative Hong Joon-Pyo, on 23.3%.
Mr Moon favours greater dialogue with North Korea, in a change to current South Korean policy.
The early election was called after a corruption scandal led to the impeachment of the former president.
Park Geun-hye is accused of allowing a close friend to extort money from companies. She denies all wrongdoing.
If Mr Moon’s victory is confirmed, he is likely to be sworn in on Wednesday.
The exit poll was conducted jointly by three network TV stations.
Change is coming: analysis by Stephen Evans, BBC News, Seoul
A Moon Jae-in presidency would represent a real shift in attitude towards North Korea. His policy is to increase contact with North Korea, in contrast to the tighter sanctions of the last ten years. He is unhappy about the deployment of a US anti-missile system on South Korean soil.
When Mr Moon was last in government, in the early 2000s, South Korea had a “Sunshine Policy” which meant co-operation with North Korea, a policy which was abandoned as North Korea tested nuclear weapons.
As policy in South Korea looks like shifting, many sceptics remain who think that no amount of talking to Kim Jong-un will persuade him to renounce either his despotic power or his nuclear ambitions.
For the last eight years, Seoul and Washington have been in lock-step over North Korea, with ever tighter sanctions and isolation. That is not Mr Moon’s way. Is it Donald Trump’s?
Who is Moon?
The son of refugees from North Korea, Mr Moon was jailed while a student in the 1970s for leading protests against military ruler Park Chung-hee – Ms Park’s father.
Later, he served in South Korea’s special forces before becoming a human rights lawyer.
Mr Moon, of the centre-left Democratic Party, unsuccessfully ran against Ms Park in 2012 elections.
He has positioned himself as the man who can move the country on from the scandals of Ms Park’s era.
“I feel that not only my party and myself but also the people have been more desperate for a change of government,” he said while casting his vote.
What are his policies?
Mr Moon has advocated greater dialogue with the North while maintaining pressure and sanctions, in contrast to Ms Park who cut almost all ties.
He has been critical of the two previous conservative administrations for failing to stop North Korea’s weapons development.
But while tensions on the Korean peninsula ensured the election was closely watched, for South Koreans the priority has been corruption and the economy, with youth unemployment stubbornly high.
Mr Moon has talked of reforming South Korea’s huge family-run conglomerates, known as chaebols, which dominate the domestic economy.