A former CIA agent has finally confirmed what the world has long suspected: the US agency was behind the arrest that put Nelson Mandela in prison for 27 years.

Two weeks before “unrepentant” 88-year-old Donald Rickard died, the CIA spy confessed to filmmaker John Irvin that his tip led to Mandela’s arrest, according to a report in the Sunday Times.

Rickard defended the arrest of South Africa’s most wanted man in 1962, which he says was necessary to capture “the world’s most dangerous communist outside of the Soviet Union.”

Rickard, who was officially working as US vice consul in the South African city of Durban at the time, said he learned Mandela was on his way to Natal, travelling between Johannesburg and Durban.

"I found out when he was coming down and how he was coming... that's where I was involved and that's where Mandela was caught,” said Rickard, according to France24.

The former spy didn’t explain how he received the information, but said he believed Mandela was “completely under the control of the Soviet Union, a toy of the communists” and about “to incite” the people of Natal into a mass rebellion against the apartheid regime.

READ MORE: ​CIA sued for records on possible role in Nelson Mandela arrest

“Natal was a cauldron at the time,” said Rickard, “and Mandela would have welcomed a war. If the Soviets had come in force, the United States would have had to get involved, and things could have gone to hell.”

“We were teetering on the brink here and it had to be stopped, which meant Mandela had to be stopped. And I put a stop to it,” he added.

The arrest led to Mandela spending almost 28 years in prison before becoming South Africa’s first post-apartheid president in 1994, and one of the most revered human rights activists in history.

Filmmaker Irvin is recreating Mandela's final months leading up to the arrest in the biopic Mandela’s Gun, and plans on previewing his production during this week’s Cannes festival.

Transparency activist Ryan Shapiro in the US launched legal action against the FBI, CIA and the National Security Agency in 2014 over the agencies’ failures to furnish US government documents from the period of Mandela’s arrest through Freedom of Information Act (FOIA) requests.

In March 2016, a District Court judge ruled against the CIA’s attempts to have the legal action dismissed, saying the agency should honor Shapiro’s FOIA request.

READ MORE: NSA, CIA, FBI sued for refusing to disclose Mandela records