SEOUL, Korea, Republic Of -- Hours after celebrating his election win with thousands of supporters in wet Seoul streets, new South Korean President Moon Jae-in on Wednesday was quickly thrown into the job of navigating a nation deeply split over its future and faced with growing threats from North Korea and an uneasy alliance with the United States.

Moon, whose victory capped one of the most turbulent political stretches in the nation's recent history and set up its first liberal rule in a decade, began his duties as president after the National Election Commission officially declared him as winner after a morning meeting.

The election body had finished counting votes as of 6 a.m. and said Moon gathered 41 per cent of the votes, comfortably edging conservative Hong Joon-pyo and centrist Ahn Cheol-soo, who gathered 24 per cent and 21 per cent of the votes, respectively.

"The National Election Commission, based on the first clause of Article 187 of the Public Official Election Law, determines that the Democratic Party's Moon Jae-in, who gathered the largest number of valid votes, was elected as president," NEC Chairman Kim Yong-deok said in the televised meeting.

Shortly after the NEC declared him as winner, Moon, as the new commander in chief of the country's military, received a call from Army Gen. Lee Sun-jin, chairman of South Korea's Joint Chiefs of Staff, who briefed him on the military's preparedness against North Korea, a Democratic Party official said.

Moon also during the morning was expected to visit the National Cemetery in the central city of Daejeon, where the country's independence fighters and war heroes are buried, before returning to capital Seoul around noon to take an oath of office at the National Assembly.

There were also expectations that Moon would announce his nominee for prime minister, the country's No. 2 job that requires approval from lawmakers, and name his presidential chief of staff during the day.

South Korea might see a sharp departure from recent policy under Moon, who 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.

This softer approach might put him at odds with South Korea's biggest ally, the United States. The 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's presidency foregoes 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. While this means Moon would have to initially depend on Park's Cabinet ministers and aides, the expectations were that he would move quickly to replace them with people of his own.

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

After exit polls indicated to his victory Tuesday night, 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.

"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."

Over the last six months, millions gathered in protest after corruption allegations surfaced against Park, who was then impeached by parliament, formally removed from office by a court and arrested and indicted by prosecutors.

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, the conservative, is an outspoken former provincial governor who pitched himself as a "strongman," described the election as a war between ideologies and questioned Moon's patriotism.

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.

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 U.S. President Donald 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.

Associated Press writer Kim Tong-hyung contributed to this report.