South Korea's election body has officially declared liberal Moon Jae-in as the country's new president a day after millions voted in an election to replace ousted former leader Park Geun-hye, who now awaits a trial over corruption charges in jail.

The National Election Commission finished counting votes earlier on Wednesday local time and said Moon gathered 41 per cent of the votes, comfortably edging his closest rival, conservative Hong Joon-pyo, who gathered 24 percent of the votes.

Moon declared victory Tuesday after his two main rivals conceded, capping one of the most turbulent political stretches in the nation's recent history and setting up its first liberal rule in a decade.

Moon, a liberal former human rights lawyer who was jailed as a student by a previous dictatorship, favours closer ties with North Korea, saying hard-line conservative governments did nothing to prevent the North's development of nuclear-armed missiles and only reduced South Korea's voice in international efforts to counter North Korea.

The White House congratulated Moon on his election.

White House press secretary Sean Spicer noted in a statement South Korea's "peaceful, democratic transition of power" and said the administration looks forward to working with Moon "to continue to strengthen the alliance" between the two countries.

South Korea is a key U.S. ally in its push to get North Korea to rid itself of its nuclear and ballistic weapons program.

Yet Moon's softer approach might put him at odds with the United States. The Donald Trump administration has swung between threats and praise for North Korea's leader.

Moon, the child of refugees who fled North Korea during the Korean War, will lead a nation shaken by a scandal that felled his conservative predecessor, Park Geun-hye, who sits in a jail cell awaiting a corruption trial later this month.

Moon smiled and waved his hands above his head as supporters chanted his name at Gwanghwamun square in central Seoul, where millions of Koreans had gathered for months starting late last year in peaceful protests that eventually toppled Park.

SOUTHKOREA-ELECTION/

Moon Jae-in emerged as the clear favourite as conservative forces struggled to regroup after the huge corruption scandal that ended Park Geun-hye's presidency. (Kim Kyung-Hoon/Reuters)

"It's a great victory by a great people," Moon told the crowd. "I'll gather all of my energy to build a new nation."

Prime Minister Justin Trudeau issued a statement congratulating Moon on his election victory.

"Canada and the Republic of Korea enjoy a close relationship, based on our strategic partnership, a modern free-trade agreement and common values," Trudeau said in the statement. 

"Canada remains steadfast in its support of the Republic of Korea and will continue to work with our international partners to enhance peace and security in the Asia-Pacific region, including on the Korean Peninsula."

Tuesday's election saw strong turnout — about 77 per cent of 42.5 million eligible voters. Moon had a relatively low share of the total vote — 41.4 per cent according to an exit poll — but there were many more major candidates than in 2012, when Park won 51.5 per cent, beating Moon by about a million votes.

Moon's two biggest rivals, conservative Hong Joon-pyo and centrist Ahn Cheol-soo, were expected to garner 23.3 per cent and 21.8 per cent, respectively, according to the exit poll, which had a margin of error of 0.8 percentage points.

Moon immediately assumed his presidential duties after the election commission finished the vote count and declared the winner Wednesday morning. This forgoes the usual two-month transition because Tuesday's vote was a byelection to choose a successor to Park, whose term was to end in February 2018.

Moon will still serve out the typical single five-year term.

Moon was chief of staff for the last liberal president, the late Roh Moo-hyun, who sought closer ties with North Korea by setting up large-scale aid shipments to the North and by working on now-stalled joint economic projects.

Hong, an outspoken former provincial governor who pitched himself as a "strongman," described the election as a war between ideologies and questioned Moon's patriotism.

South Korea Election

A boy looks out from the polling booth while his mother casts ballot for presidential election at a local polling station in Seoul on Tuesday. (Lee Jin-man/Associated Press)

After voting, Hong said the election was a "war of regime choices between people, whether they decide to accept a North Korea-sympathizing leftist government or a government that can protect the liberty of the Republic of Korea," South Korea's formal name.

Park's trial later this month on bribery, extortion and other corruption charges could send her to jail for life if she is convicted. Dozens of high-profile figures, including Park's longtime confidante, Choi Soon-sil, and Samsung's de facto leader, Lee Jae-yong, have been indicted along with Park.

Moon frequently appeared at anti-Park rallies and the corruption scandal boosted his push to re-establish liberal rule. He called for reforms to reduce social inequalities, excessive presidential power and corrupt ties between politicians and business leaders. Many of those legacies dated to the dictatorship of Park's father, Park Chung-hee, whose 18-year rule was marked by both rapid economic rise and severe civil rights abuse.

As a former pro-democracy student activist, Moon was jailed for months in the 1970s while protesting against the senior Park.

South Korea Elections

South Korean presidential candidate Hong Joon-pyo of the Liberty Korea Party, described the election as a war between ideologies and accused Moon of being aligned with North Korea. (Ahn Young-joon/Associated Press)

Many analysts say Moon likely won't pursue drastic rapprochement policies because North Korea's nuclear program has progressed significantly since he was in the Roh government a decade ago.

A big challenge will be the U.S. under Trump, who has proven himself unconventional in his approach to North Korea, swinging between intense pressure and threats and offers to talk.

"South Koreans are more concerned that Trump, rather than North Korean leader Kim Jong-un, will make a rash military move, because of his outrageous tweets, threats of force and unpredictability," Duyeon Kim, a visiting fellow at the Korean Peninsula Future Forum in Seoul, wrote recently in Foreign Affairs magazine.

"It is crucial that Trump and the next South Korean president strike up instant, positive chemistry in their first meeting to help work through any bilateral differences and together deal with the North Korean challenge," she said.

With files from CBC News