GOYANG, South Korea – The leaders of North and South Korea made a bold pledge Friday to work toward a "common goal" of denuclearizing their peninsula and formally ending the Korean War by the end of this year, following a historic day of talks on the border that has divided them for almost seven decades.

It was a day marked by an astonishing level of congeniality between the two, including a warm embrace at the signing of what they called the "Panmunjeom Declaration, after the border area where it was forged. It was, however, short on details as to what, exactly, "denuclearization" means for each of them.

Still, the fact that Kim Jong Un and Moon Jae-in spent so much time together and came up with a joint statement that even includes the word "denuclearization" marks a surprising development after a year of threats and missile launches that brought the specter of war back to the Korean Peninsula.

"You can't ask for more than that," said John Delury, a professor of international relations at Yonsei University in Seoul and a keen proponent of diplomatic engagement.

The warmth of the meeting and the positive, if vague, signals now set the stage for Kim to meet with President Trump at the end of May or early June. Trump has said he will only go to the talks if they promise to be "fruitful," a bar that likely was met with Friday's meetings.

"Yes, there are still questions about how to guarantee North Korea's security on the path the denuclearization. But I'm surprised they would go this far at this early stage, that Kim Jong Un didn't save this for his meeting with Trump," Delury said.

The three-page Panmunjeom Declaration states that "South and North Korea confirmed the common goal of realizing, through complete denuclearization, a nuclear-free Korean Peninsula."

"South and North Korea shared the view that the measures being initiated by North Korea very meaningful and crucial for the denuclearization of the Korean Peninsula and agreed to carry out their respective roles and responsibilities in this regard," it said. "South and North Korea agreed to actively seek the support and cooperation of the international community for the denuclearization of the Korean Peninsula."

Kim did not utter the word "denuclearization" during his remarks with Moon after the signing ceremony, and the phrase "through complete denuclearization" will ring alarm bells in Washington because it implies that nuclear weapons will not be allowed in South Korea either.

The United States, South Korea's security ally, regularly sends nuclear-capable aircraft and ships to the South during military exercises, so this clause will raise suspicions that North Korea is calling for a significant change in the U.S.-South Korea alliance.

Moon had previously said that Kim would not insist on American troops being withdrawn from the South.

In Friday's declaration, Kim and Moon also agreed to work to turn the armistice agreement that ended the Korean War in 1953 into a peace treaty that would officially bring the war to a close.

"South and North Korea will actively cooperate to establish a permanent and solid peace regime on the Korean Peninsula," the joint statement said in English, as officially translated by the South's presidential Blue House.

The Korean language version used the words "peace treaty" – an important distinction. "Treaty" generally refers to a piece of paper while "regime" means a system for peace, such as stopping military activities.

"Bringing an end to the current unnatural state of armistice and establishing a robust piece regime on the Korean Peninsula is a historical mission must not be delayed any further," the statement said.

The United States signed the armistice agreement on behalf of the South Korean side, and Trump has said that he supports such a move.

The White House welcomed Friday's summit as it started.

"We wish the Korean people well," press secretary Sarah Huckabee Sanders said in a statement.

"We are hopeful that talks will achieve progress toward a future of peace and prosperity for the entire Korean Peninsula," she said, adding that the White House hoped the "robust discussions" would pave the way for the planned meeting between Trump and Kim.

"This provides the political space for Trump to have his own summit with Kim," said Duyeon Kim, a visiting fellow at the Korean Peninsula Future Forum in Seoul. "Whether or not Kim Jong Un means it is a completely different story."

The two sides will set up an inter-Korean liaison office to be established in Kaesong, a city just over the northern side of the border, and Moon said he would visit Pyongyang this fall.

During their conversations earlier in the day, Kim said he would happily travel to Seoul if invited.

The signing ceremony came at the end of an extraordinary day full of scenes that would have been unimaginable at the turn of the year – after a 2017 in which Kim had demonstrated surprising advances in both missile and nuclear technology and was regularly threatening to use them against the United States.

Trump, for his part, was returning the verbal volleys, calling Kim "little rocket man" and threatening to "totally destroy" North Korea.

But, following a sudden frenzy of diplomacy pegged to the Winter Olympics that South Korea hosted in February, Moon has managed to shift Kim's focus from missile launches to the negotiating table.

At 9:30 a.m. on Friday morning, Kim came out of the main building on the northern side of the military demarcation line that has divided the Korean Peninsula for 65 years and walked right up to the line.

Moon was waiting there for him, hand outstretched, and for the first time since the Korean War halted in 1953, a North Korean leader stepped into South Korea. Showing his penchant for bold and surprising moves – a tactic that was repeated later with the hug – Kim then asked Moon to step back across the line with him, and he did. For a brief moment, the leaders stood in North Korean territory, holding hands.

The moment was broadcast live across the country, with commuters stopping in train stations and teachers stopping classes so their students could watch the moment, and North Korean state television even broadcast an unscheduled news bulletin to announce that Kim was on his way to Panmunjeom.

Moon and Kim proceeded to spend hours together on Friday, both in formal talks and in a half-hour-long private discussion on park benches outside in the sun, surrounded by birdsong. They threw soil and water from both Koreas onto a pine tree planted in the Demilitarized Zone to mark the occasion.

At one stage during the day, Kim assured Moon he wouldn't have to wake up early any more – a reference to the fact that North Korea's missile launches usually happened at about dawn.

Then, after their announcement, their wives made cordial small-talk in front of the cameras before heading to a dinner that was full of symbolism, from the noodles that came from Pyongyang to the fish brought in from Moon's home town.

This is only the third inter-Korean summit and is the first that South Korea has hosted.

In 2000, the South Korean president at the time, Kim Dae-jung, went to Pyongyang to meet then-leader Kim Jong Il, the current leader's father, and was awarded the Nobel Peace Prize for his efforts. However, the shine came off when it emerged the South had paid the North $500 million to participate.

Roh Moo-hyun, Kim Dae-jung's successor, followed suit by traveling to Pyongyang in 2007 and also meeting Kim Jong Il. At the time, Moon was Roh's chief of staff and head of the summit preparation committee.