South Korea's president shocked the country on Tuesday night when, out of the blue, he declared martial law in the Asian democracy for the first time in nearly 50 years.
Yoon Suk-yeol's drastic decision - announced in a late-night TV broadcast - mentioned "anti-state forces" and the threat from North Korea.
But it soon became clear that it not been spurred by external threats but by his own desperate political troubles.
Still, it prompted thousands of people to gather at parliament in protest, while opposition lawmakers rushed there to push through an emergency vote to remove the measure.
Defeated, Yoon emerged a few hours later to accept the parliament's vote and lift the martial law order.
How did it all unfold?
Yoon has acted like a president under siege, observers say.
In his address on Tuesday night, he recounted the political opposition's attempts to undermine his government before saying he was declaring martial law to "crush anti-state forces that have been wreaking havoc".
His decree temporarily put the military in charge - with helmeted troops and police deployed to the National Assembly parliament building where helicopters were seen landing on the roof.
Local media also showed scenes of masked, gun-toting troops entering the building while staffers tried to hold them off with fire extinguishers.
Around 23:00 local time on Tuesday (14:00 GMT), the military issued a decree banning protests and activity by parliament and political groups, and putting the media under government control.
But South Korean politicians immediately called Yoon's declaration illegal and unconstitutional. The leader of his own party, the conservative People's Power Party, also called Yoon's act "the wrong move".
Meanwhile, the leader of the country's largest opposition party, Lee Jae-myung of the liberal Democratic Party, called on his MPs to converge on parliament to vote down the declaration.
He also called on ordinary South Koreans to show up at parliament in protest.
"Tanks, armoured personnel carriers and soldiers with guns and knives will rule the country... My fellow citizens, please come to the National Assembly.”
Thousands heeded the call, rushing to gather outside the now heavily- guarded parliament. Protesters chanted: "No martial law!" and "strike down dictatorship".
Local media broadcasting from the site showed some scuffles between protesters and police at the gates. But despite the military presence, tensions did not escalate into violence.
And lawmakers were also able to make their way around the barricades - even climbing fences to make it to the voting chamber.
Shortly after 01:00 on Wednesday, South Korea's parliament, with 190 of its 300 members present, voted down the measure. President Yoon's declaration of martial law was ruled invalid.
How significant is martial law?
Martial law is temporary rule by military authorities in a time of emergency, when civil authorities are deemed unable to function.
The last time it was declared in South Korea was in 1979, when the country's then long-term military dictator Park Chung-hee was assassinated during a coup.
It has never been invoked since the country became a parliamentary democracy in 1987.
But on Tuesday, Yoon pulled that trigger, saying in a national address he was trying to save South Korea from "anti-state forces".
Yoon, who has taken a noticeably more hardline stance on North Korea than his predecessors, described the political opposition as North Korea sympathisers - without providing evidence.
Under martial law, extra powers are given to the military and there is often a suspension of civil rights for citizens and rule of law standards and protections.
Despite the military announcing restrictions on political activity and the media - protesters and politicians defied those orders. And there was no sign of the government seizing control of free media - Yonhap, the national broadcaster, and other outlets kept reporting as nomal.
Why was Yoon feeling pressured?
Yoon was voted into office in May 2022 as a hardline conservative, but has been a lame duck president since April when the opposition won a landslide in the country's general election.
His government since then has not been able to pass the bills they wanted and have been reduced instead to vetoing bills passed by the liberal opposition.
He has also seen a fall in approval ratings - hovering around lows of 17% - as he has been mired in several corruption scandals this year - including one involving the First Lady accepting a Dior bag, and another around stock manipulation.
Just last month he was forced to issue an apology on national TV, saying he was setting up an office overseeing the First Lady's duties. But he rejected a wider investigation, which opposition parties had been calling for.
Then this week, the opposition proposed slashing a major government budget bill - which cannot be vetoed.
At the same time, the opposition also moved to impeach cabinet members and several top prosecutors- including the head of the government's audit agency - for failing to investigate the First Lady.
What now?
Yoon's declaration caught many off guard and for a period of six hours South Koreans were in a state of confusion as to what the martial law order meant.
But the opposition was able to congregate quickly at parliament and had the numbers to vote down the declaration.
And despite the heavy presence of troops and police in the capital, a takeover by the military has, it seems, not materialised.
Under South Korean law, the government must lift martial law if a majority in parliament demands it in a vote.
The same law also prohibits martial law command from arresting lawmakers.
It's unclear what happens now and what the consequences will be for Yoon. Some of the protesters gathered outside the assembly on Tuesday night had also been shouting: "Arrest Yoon Suk-yeol".
But his rash action has certainly stunned the country - which views itself as a thriving, modern democracy that has come far since its dictatorship days.
This is being viewed as the biggest challenge to that democratic society in decades.
Experts contend it may be more damaging to South Korea's reputation as a democracy than even the 6 January riots in the US.
"Yoon’s declaration of martial law appeared to be both legal overreach and a political miscalculation, unnecessarily risking South Korea’s economy and security," one expert, Leif-Eric Easley at Ewha University in Seoul said.
"He sounded like a politician under siege, making a desperate move against mounting scandals, institutional obstruction and calls for impeachment, all of which are now likely to intensify."
As the speaker of parliament said on Wednesday: "We will protect democracy together with the people."