South Korea’s Presidential Security Service, a​n agency​ assigned to protect the president, prides itself on being the “last bastion for a safe and stable state administration.” It is now at the heart of South Korea’s biggest political mess in decades, acting as a final line of defense to prevent criminal investigators from detaining President Yoon Suk Yeol on​ charges of insurrection.

Since ​his impeachment over a short-lived martial law declaration last month, Mr. Yoon has been holed up in central Seoul, in a hilly compound that is now surrounded by barricades of buses, barbed wire and the presidential bodyguards​. He has vowed to “fight to the end” to return to office.​ But a majority of South Koreans, according to surveys, want him ousted and arrested, and a court on Tuesday granted investigators a new warrant to detain him​.

The only thing standing between them and Mr. Yoon is the Presidential Security Service, or P.S.S., which blocked the first attempt to serve the warrant last Friday. When 100 criminal investigators and police officers showed up at ​his residence, the agency’s staff outnumbered them two-to-one and held them off, questioning the legality of the court-issued document. The two sides went back-and-forth during a five-and-a-half-hour standoff, before investigators abandoned efforts to detain Mr. Yoon.

Much like the Secret Service does in the United States, the P.S.S. protects sitting and former presidents, presidents-elect and visiting heads of state. Created in 1963 under the former dictator Park Chung-hee, the P.S.S. was once one of the government’s most powerful agencies, with the military strongmen relying on its loyalty to ​escape assassination attempts. As South Korea democratized in recent decades, it had largely receded into the shadows. But under Mr. Yoon, it began ​attracting unsavory attention from the public as its agents ​​dragged away protesters during public events.

Mr. Yoon ​appointed Kim Yong-hyun, his most loyal ​ally, to serve as his first security service chief before promoting him to defense minister. Although South Korea is currently being run by an acting president after Mr. Yoon was suspended from office following his impeachment, the service has sworn to defend Mr. Yoon because he remains the sole elected leader.

The security service has warned ​that there could be a clash if investigators try again to detain Mr. Yoon​. The agency includes hundreds of trained bodyguards and anti-terrorist specialists, who are backed by detachments from the police and military​.