Pro-Russian candidate Igor Dodon has won the second round of Moldova's presidential election.
With almost all the ballots counted, Mr Dodon, who wants to restore close ties with Russia, had 52.18% of the vote. His rival, pro-European candidate Maia Sandu, polled 47.82%.
The national vote marks the first direct presidential election in Moldova for 20 years.
Since 1996 presidents of Moldova have been chosen by parliament.
The election was seen as a battle between those supporting closer ties with Russia and those wanting integration with the European Union.
Speaking shortly after the closure of polling stations on Sunday, Mr Dodon called on Ms Sandu to preserve public order and abstain from protests.
"The election is over," he said, adding: "People have elected their president." The final voter turnout was 53.54%.
How close to Moscow can he go? By Petru Clej in Chisinau
Winning an election may be the easy part of Igor Dodon's plans. He now has to fulfil promises with few constitutional powers at his disposal.
He might try to undermine the government and a pro-European majority in parliament to force early elections and help his Party of Socialists to a majority, but he won't find it straightforward.
Moldova is now dependent on EU and IMF funds to help it survive the financial shock of the "theft of the century". Last year, three banks collapsed and $1bn (£790m) disappeared - equal to about one-sixth of the country's GDP.
Moldova can ill afford foregoing financial assistance by joining the Russian-dominated Eurasian Economic Union - one of Mr Dodon's main campaign promises.
Mr Dodon's electoral success may turn out to be a largely symbolic victory that leaves Moldova bitterly divided and none the wiser about which way to turn - whether to continue its slow progress towards the EU or return to Moscow's fold.
Mr Dodon, 41, was a deputy prime minister in the Party of Communists government before 2009. He blames widespread corruption in Moldova on the pro-EU parties that have ruled the country since then.
Both candidates criticised the vote on Sunday as badly organised, highlighting the shortage of ballot papers for overseas voters.
Moldova, a former Soviet republic with has close historical ties with Moscow, declared independence after the break-up of the Soviet Union in 1991.
It also has a breakaway region supported by Russia, Trans-Dniester.
It has moved to forge closer ties with the European Union in recent years, a course championed by Ms Sandu.