SEOUL — A graft prosecutor-turned opposition leader has won an extremely close presidential election in South Korea, reinstating conservatives to power with calls for a more confrontational stance against North Korea and a stronger alliance with the United States.
With 98 percent of the votes counted, the opposition leader, Yoon Suk-yeol, was leading by a margin of 263,000 votes, or 0.8 percentage points, when his opponent conceded early Thursday. It was South Korea’s tightest race since it began holding free presidential elections in 1987.
Mr. Yoon will replace President Moon Jae-in, a progressive leader whose single five-year term ends in May.
The election was widely seen as a referendum on Mr. Moon’s government. Its failure to curb skyrocketing housing prices angered voters. So did #MeToo and corruption scandals involving Mr. Moon’s political allies, as well as a lack of progress in rolling back North Korea’s nuclear weapons program.
“This was not an election for the future but an election looking back to judge the Moon administration,” said Prof. Ahn Byong-jin, a political scientist at Kyung Hee University in Seoul. “By electing Yoon, people wanted to punish Moon’s government they deemed incompetent and hypocritical and to demand a fairer society.”
But, as the close results showed, the electorate was closely divided, with many voters lamenting a choice between “unlikables.”
Mr. Yoon’s opponent, Lee Jae-myung of the governing Democratic Party, acknowledged his country’s rifts in his concession speech. “I sincerely ask the president-elect to lead the country over the divide and conflict and open an era of unity and harmony,” he said.
The victory for Mr. Yoon, who is 61, returns conservatives back to power after five years in the political wilderness. His People Power Party had been in disarray following the impeachment of its leader, President Park Geun-hye, whom Mr. Yoon helped convict and imprison on corruption charges. Mr. Yoon, who also went after another former president and the head of Samsung, was recruited by the party to engineer a conservative revival.
The election was watched closely by both South Korea’s neighbors and the United States government. Mr. Yoon’s election might upend the current president’s progressive agenda, especially his policy of seeking dialogue and peace with North Korea. As president, Mr. Moon has met with North Korea’s leader, Kim Jong-un, three times, though that did nothing to stop Mr. Kim from rapidly expanding his nuclear weapons program.
Mr. Yoon has vehemently criticized Mr. Moon’s approach on North Korea, as well as toward China.
He insists that U.N. sanctions should be enforced until North Korea is completely denuclearized, a stance that aligns more closely with Washington’s than with Mr. Moon’s, and is anathema to North Korea. Mr. Yoon has also called for ratcheting up joint military drills between South Korea and the United States — which were scaled down under Mr. Moon — another stance likely to rile North Korea, which may now raise tensions through more weapons tests.
“Peace is meaningless unless it is backed by power,” Mr. Yoon said during the campaign. “War can be avoided only when we acquire an ability to launch pre-emptive strikes and show our willingness to use them.”
Mr. Moon has kept a balance between the United States, South Korea’s most important ally, and China, its biggest trading partner — an approach known as “strategic ambiguity.” Mr. Yoon said he would show “strategic clarity,” and favor Washington. He called the rivalry between the two great powers “a contest between liberalism and authoritarianism.”
North Korea will likely pose Mr. Yoon’s first foreign policy crisis.
It has conducted a flurry of missile tests this year and might consider Mr. Yoon’s confrontational rhetoric the prod it needs to escalate tensions further.
“We will see North Korea return to a power-for-power standoff, at least in the early part of Yoon’s term,” said Lee Byong-chul, a North Korea expert at Kyungnam University’s Institute for Far Eastern Studies in Seoul.
Mr. Yoon served as prosecutor general under Mr. Moon. His political stock rose among conservative South Koreans when he resigned last year and became a bitter critic of his former boss. Pre-election surveys had indicated that South Koreans would vote for Mr. Yoon less because they liked him than to show their anger at Mr. Moon and his Democratic Party.
“This was such a hot and heated race,’’ Mr. Yoon told a gathering of supporters at the National Assembly Library. “But the competition is over and now it’s time for us to join our forces together for the people and the nation.”
“We are the betrayed generation,” said Kim Go-eun, 31, who works for a convenience store chain. “We have been taught that if we studied and worked hard, we would have a decent job and economically stable life. None of that has come true.
“No matter how hard we try, we don’t see a chance to join the middle class,” she said.
The campaign also exposed a nation deeply divided over gender conflicts. Mr. Yoon was accused of pandering to widespread sentiment against China and against feminists among young men, whose support proved crucial to his victory. Exit polls showed the voters in their 20s split sharply along the gender line, with men favoring Mr. Yoon and women Mr. Lee.
Young men said they were gravitating toward Mr. Yoon because he spoke to some of their deepest concerns, like the fear that an influx of immigrants and a growing feminist movement would further erode their job opportunities. Professor Ahn likened the phenomenon to “Trumpism.”
“We may not be completely satisfied with Yoon, but he is the only hope we’ve got,” said Kim Seong-heon, 26, a university student in Seoul who lives in a windowless room barely big enough to squeeze in a bed and closet.
Mr. Yoon promised deregulation to spur investment. He also promised 2.5 million new homes to make housing more affordable.
But the newly elected president may face fierce resistance at the National Assembly, where Mr. Moon’s Democratic Party holds a majority. Mr. Yoon’s campaign promise to abolish the country’s ministry of gender equality may prove particularly contentious.
He also has to contend with a bitter, disillusioned public.
New allegations of legal and ethical misconduct emerged almost daily to cast doubt on Mr. Yoon and his wife, Kim Keon-hee, as well as on his rival, Mr. Lee.
Many voters felt they were left with an unappealing choice.
“It was not about whom you liked better but about whom you hated less,” said Jeong Sang-min, 35, a logistics official at an international apparel company.