South African security forces had only days to implement a rough plan for Nelson Mandela's grand funeral, based partly on blueprints of past major events like the 2010 World Cup final.
South Africa's first black president had been seriously ill for some time, but his death still posed a major organisational challenge as a small army of world leaders, dignitaries and celebrities asked to attend the state send-off.
Security preparations which would normally take months for the likes of US President Barack Obama had to be compressed into a few days.
And as well as foreign VIPs, there was also the question of hundreds of thousands of South Africans who wanted an opportunity to say a final farewell to the man who led them out of the apartheid era.
In terms of crowd control, the security authorities have largely relied on the experience they gained during the World Cup nearly four years ago.
Around 80,000 people will attend a memorial service tomorrow at the Soweto stadium that hosted the 2010 final.
After that, Mandela's body will lie in state for three days in Pretoria before being taken for burial Sunday in his rural boyhood home of Qunu.
Areas around all three venues will be subjected to different levels of security lockdown, with flight restrictions in force around Mthatha, the nearest airport to Qunu.
Analyst Johan Burger from the Institute for Security Studies in Pretoria, said a basic security blueprint "has been existing for some time now."
"Now they have to fill in the numbers and the names and allocate the tasks to the specific commanders," Burger said.
Many of the more than 90 world leaders attending the various events will bring their own security teams, said Solomon Makgale, spokesman for the National Joint Operational Centre (Natjoints), which coordinates between the police, military and intelligence agencies.
"All of them always come with their security detail, then they work with us," he said.
Almost 60 heads of state and government had attended Mandela's inauguration as South Africa's first black president in 1994.
Security forces' leave has been cancelled until after Sunday's burial, and around 11,000 soldiers have been deployed to back up police operations.
In a bid to prevent dangerously large crowds gathering at the actual event venues, large screens carrying live broadcasts have been installed at sites all over the country.
Some 3,000 marshalls will be engaged in crowd control at the Soweto stadium, which will be surrounded by three concentric security circles of increasing scrutiny, with vehicle access severely restricted.
The same system will apply for Mandela's lying in state at the Union Buildings, the seat of government in Pretoria where he was inaugurated 19 years ago.
In terms of working with the US Secret Service, the process has been eased by the fact that Obama made an official visit to South Africa just five months ago.
"It has meant that everybody is familiar with their counterparts and we've been working with a lot of experience on both sides," said US embassy spokesman Jack Hillmeyer.
The government has sought to discourage foreign leaders from attending the burial in Qunu, citing its rural location, lack of amenities and limited space.
The immediate area around the Mandela family farm has already been cordoned off.