WASHINGTON — North Korea’s leader, Kim Jong-un, has invited President Trump to meet for negotiations over its nuclear program, an audacious diplomatic overture that would bring together two strong-willed, idiosyncratic leaders who have traded threats of war.

“He expressed his eagerness to meet President Trump as soon as possible,” Mr. Chung said at the White House on Thursday evening after meeting the president. Mr. Trump, he said, agreed to “meet Kim Jong-un by May to achieve permanent denuclearization.”

“Also, no missile testing by North Korea during this period of time,” Mr. Trump added. “Great progress being made but sanctions will remain until an agreement is reached. Meeting being planned!”

Mr. Chung, whose talks with Mr. Kim on Monday in Pyongyang resulted in the invitation, noted that the North Korean leader said he understood that joint military exercises with the United States and South Korea would go ahead as scheduled after the end of the Paralympic Games this month.

For Mr. Trump, a meeting with Mr. Kim, a leader he has threatened with “fire and fury” and has derided as “Little Rocket Man,” is a breathtaking gamble. No sitting American president has ever met a North Korean leader, and Mr. Trump himself has repeatedly vowed that he would not commit the error of his predecessors by being drawn into a protracted negotiation in which North Korea extracted concessions from the United States but held on to key elements of its nuclear program.

Meeting Mr. Kim now, rather than at the end of a negotiation when the United States would presumably have extracted concessions from North Korea, is an enormous gesture by the president. But Mr. Trump and Mr. Kim share a penchant for bold, dramatic moves, and their personal participation in a negotiation could take it in unexpected directions.

The announcement itself was delivered in an improvisational style that belied its historic significance. Mr. Trump himself teased the news, popping into the White House briefing room shortly after 5 p.m. to tell reporters that South Korea would make a major announcement at 7.

Then the White House left it to Mr. Chung, who is President Moon Jae-in’s national security adviser, to deliver the news to reporters, standing in the darkened driveway in front of the West Wing. The White House later confirmed Mr. Trump’s plan to meet Mr. Kim in a statement from the press secretary, Sarah Huckabee Sanders.

Behind the scenes, events unfolded even more haphazardly. Mr. Trump was not scheduled to meet Mr. Chung until Friday, but when he heard that the envoy was in the West Wing seeing other officials, the president summoned him to the Oval Office, according to a senior administration official.

Mr. Trump, the official said, then asked Mr. Chung to tell him about his meeting with Mr. Kim. When Mr. Chung said that the North Korean leader had expressed a desire to meet Mr. Trump, the president immediately said he would do it, and directed Mr. Chung to announce it to the White House press corps.

Mr. Chung, nonplused, said he first needed approval from Mr. Moon, who quickly granted it in a phone call. Mr. Trump later called Prime Minister Shinzo Abe of Japan, and the two discussed coordinating diplomatic efforts. Mr. Trump also plans to call President Xi Jinping of China.

By day’s end, dazed White House officials were discussing whether Mr. Trump would invite Mr. Kim to come to the United States. That seemed entirely likely, the senior administration official said, though American officials doubt the North Korean leader would accept.

White House officials had expected to deliberate for several days over how to respond to North Korea’s proposal for direct talks between the countries, which South Korean officials had first conveyed by telephone this week. But Mr. Kim’s offer of a leader-to-leader meeting accelerated, if not upended, the administration’s plans.

Embarking on a high-level negotiation will pose a stiff challenge to the administration, which has built its North Korea policy around imposing crippling sanctions, backed by the threat of military action. People briefed by the administration said it had done little planning for how a negotiation with the North would unfold.

The State Department’s chief North Korea negotiator, Joseph Yun, recently announced his departure from the Foreign Service. The White House also scotched a plan to nominate another experienced negotiator, Victor Cha, as ambassador to Seoul.

North Korea, by contrast, appears to have planned its diplomatic overture methodically, starting with Mr. Kim’s conciliatory message toward the South in his New Year’s Day address, and continuing through the North’s charm offensive during the Winter Olympic Games in Pyeongchang, South Korea.

The South Korean envoys visited the White House on Thursday to brief Mr. Trump and his staff on their meeting with Mr. Kim, which was the first between South Korean officials and Mr. Kim. While they said they were carrying additional messages from North Korea, an American official said that the envoys did not deliver a letter from Mr. Kim.

In South Korea, people greeted the news of a meeting between Mr. Kim and Mr. Trump with relief. South Koreans had nervously watched the Korean Peninsula edge toward the brink of a possible military conflict last year.

“We hope that these developments will become an important turning point for realizing the denuclearization of the Korean Peninsula and firmly establishing peace there,” Lee Yu-jin, a government spokeswoman, said Friday.

Since taking power last May, Mr. Moon has repeatedly called for a dialogue with North Korea, even as Mr. Trump has escalated pressure on the North with increasingly harsh sanctions, more vigorous military maneuvers and a string of hostile tweets.

Mr. Kim rattled the region last year with a series of nuclear and long-range missile tests. Then he suddenly responded to Mr. Moon’s overtures for dialogue, in which he proposed talks with South Korea, saying he was willing to send athletes to the Olympics.

The two Koreas have also exchanged high-level envoys in recent weeks, including Mr. Kim’s sister, Kim Yo-jong, who met Mr. Moon in Seoul last month.

Analysts expressed skepticism about Mr. Trump’s decision to meet Mr. Kim, saying there was no indication that North Korea had given up its determination to be a nuclear weapons state.

“There is every reason to believe that North Korea is attempting to blunt sanctions and secure de facto legitimacy for its nuclear weapons program with this gesture,” said Michael J. Green, a former Asia adviser to President George W. Bush, speaking by telephone from Tokyo.

Evan S. Medeiros, an Asia adviser to President Barack Obama, said that any direct talks would elevate Mr. Kim and legitimize him. “We got nothing for it. And Kim will never give up his nukes,” Mr. Medeiros said. “Kim played Moon and is now playing Trump.”

This week, administration officials had spoken in scathing terms about North Korea’s offer of direct talks. They noted that Mr. Kim said nothing about halting the production of nuclear bombs or missiles during negotiations — which meant the North could build its arsenal while stringing out the talks.

It seemed that the only thing that changed was Mr. Kim’s invitation to meet Mr. Trump himself. The president’s deal-making skills, one of his aides said on Thursday, could produce an outcome different from previous rounds of diplomacy, which have always ended in failure and disappointment.

The highest-level American official to meet with a North Korean leader was Secretary of State Madeleine K. Albright, who visited Pyongyang in 2000, near the end of the Clinton administration. Dr. Albright had planned to arrange a visit by President Bill Clinton.

But it fell apart when Kim Jong-il, the father of the current leader, would not agree to a missile deal in advance; he wanted to negotiate it face-to-face with the president. Mr. Clinton decided not to take the risk, skipped the trip, and used his last weeks in office to make a race for Middle East peace instead.

Correction:March 8, 2018

An earlier version of this article misstated the country with which the United States will take part in joint military exercises. It is South Korea, not North Korea.

Reporting was contributed by Choe Sang-Hun from Seoul, South Korea, and Peter Baker, David E. Sanger and Michael D. Shear from Washington.