North and South Korea took a step back from a looming military clash on Saturday, agreeing to hold top-level talks as their respective armies faced off across the border on maximum alert.
The agreement on the talks -- to be held at the border truce village of Panmunjom -- came just hours before the expiry of a North Korean ultimatum for Seoul to halt loudspeaker propaganda broadcasts across the border or face military action.
The four delegates -- two from each side -- will include the South Korean president's national security adviser, Kim Kwan-Jin, and the man widely seen as North Korean leader Kim Jong-Un's number two, Hwang Pyong-So.
The presidential Blue House in Seoul said the talks were set to begin at 6:00pm (0900 GMT).
The announcement came with both Koreas bracing for a confrontation as the clock ticked down to the North's 0830 GMT deadline.
Seoul had insisted it would not accede to Pyongyang's demand to turn off the loudspeakers which have been blasting propaganda messages into North Korea for the past week.
The North Korean People's Army (KPA) said it had moved into a "fully armed, wartime state" on the orders of Kim Jong-Un, while the foreign ministry in Pyongyang warned Saturday that the situation had "reached the brink of war" and was "hardly controllable".
The international community has long experience of North Korea's particularly aggressive brand of diplomatic brinkmanship, and the last minute decision for a dialogue will confirm for many that this has largely been another exercise in attention-seeking by Pyongyang.
For the moment, there has been little sense of panic among ordinary South Koreans who have become largely inured over the years to the North's regular -- and regularly unrealised -- threats of imminent war.
But the military has been on maximum alert, and US and South Korean jets flew simulated bombing sorties around midday Saturday in a clear show of defiance and force.
The Yonhap news agency quoted military sources as saying the North, meanwhile, had towed artillery units close to the border for a possible strike against the military loudspeaker units.
Technically, the two Koreas have been at war for the past 65 years, as the 1950-53 Korean conflict ended with a ceasefire that was never ratified by a formal peace treaty.
The last direct attack on the South was in November 2010 when North Korea shelled the South Korean border island of Yeonpyeong, killing two civilians and two soldiers.
Kim Jong-Un's order to move to a war footing came after an exchange of artillery fire on Thursday that claimed no casualties but triggered a dangerous spike in cross-border tensions.
Tensions were already running high over mine blasts this month that maimed two South Korean border soldiers, and the launch last Monday of an annual South Korea-US military exercise that infuriated Pyongyang.
Despite Pyongyang's subsequent denials, South Korea said the North was behind the blasts and responded by resuming the propaganda broadcasts across the border -- a practice both Koreas had ended by mutual consent in 2004.
The move outraged the North and prompted its 48-hour ultimatum for the South to turn off the loudspeakers by Saturday afternoon.
On Friday, President Park Geun-Hye appeared on television, wearing army fatigues and telling top military commanders that further North Korean provocations "will not be tolerated".
The situation is being closely watched, with UN chief Ban Ki-moon calling for restraint from both sides and the United States urging Pyongyang to avoid further escalation.
There are nearly 30,000 US troops permanently stationed in South Korea, and the US military's top officer on Saturday reiterated Washington's commitment to the defence of its ally.
A call for calm and restraint also came from China, the North's main diplomatic protector and economic supporter.
Ties between Beijing and Pyongyang have become strained, and China will be keen to avoid any regional flare-up as it seeks to attract world leaders to Beijing next month for a three-day celebration of Japan's defeat in World War II.
The last talks to be held in Panmunjom were in October, when military officials from both sides met to discuss a variety of issues affecting cross-border tension.