President Obama speaks while the sign interpreter Thamsanqa Jantjie (R), stands next to him during the a speech at the Nelson Mandela Memorial at FBN Stadium, Johannesburg, South Africa, on Dec. 12. (STR/EPA)

The U.S. Secret Service team that landed in Johannesburg to prepare for President Obama’s visit after the death of Nelson Mandela thought it knew what to expect.

The same agents had just been to the city during Obama’s trip there in late June. In a briefing, South African officials pledged to secure FNB Stadium — the site of Mandela’s memorial service — and conduct all necessary background checks, according to a U.S. official familiar with the planning.

But once Obama arrived for a whirlwind 13-hour visit on Dec. 10, it became clear that South African security would not live up to the promises, the official said. Obama’s motorcade proceeded on highways with heavy traffic, many people attending the service did not go through metal detectors and large crowds gathered near the stage full of dignitaries, with few South African security officers nearby.

The problems climaxed with revelations that the sign-language interpreter employed for the memorial — who stood within arm’s length of Obama and other speakers — had allegedly faked his credentials, suffered from schizophrenia and been accused of murder.

“They said they would do A, B, C and D, but it was clear the threshold was not met,” said the U.S. official, who spoke on condition of anonymity to speak bluntly about the situation. “The South African government made the plans. They needed to execute them.”

Former agents and government officials said the events in Johannesburg illustrate the challenges and unpredictability of protecting the U.S. president on foreign soil, where American officials must rely heavily on local governments and negotiations over security protocols are often fraught with sensitive diplomatic considerations.

There is no evidence that Obama was threatened by the close proximity of Thamsanqa Jantjie, who did not use recognizable sign language during the speeches and later said he was hallucinating. Secret Service spokesman Ed Donovan emphasized that U.S. agents were in close proximity to Obama at all times and that the president was never in jeopardy.

Donovan declined to say whether Jantjie’s record of murder charges was discovered by South African authorities ahead of time. The Associated Press reported this week that friends and relatives said Jantjie was among a group that burned two men to death in 2003.

“They worked very hard on this trip, which came about on short notice,” White House press secretary Jay Carney said of the Secret Service. “But they, as they always do, took the precautions necessary to ensure the president’s safety.”

The U.S. official familiar with the Secret Service’s planning emphasized that the agency had contingencies to ensure Obama’s safety despite the South African breakdowns.

“We take extraordinary measures so that, even if it’s not exactly the way we want and we have to be flexible, we can react,” the official said. “If security degraded to the point where safety was a factor, we would move him.”

Dave Wilkinson, a former Secret Service agent in the presidential protection division who retired in 2005 and now is president of the Atlanta Police Foundation, said that “one of the most harrowing things” about foreign visits is their unpredictability.

“You can talk and talk and talk and commit and confirm every bit of the security procedures, but until game day you don’t know what’s going to roll out,” Wilkinson said.

Consider a speech by then-President George W. Bush in Tbilisi, Georgia, in the spring of 2005. A crowd estimated between 150,000 and 250,000 people surged into Freedom Square, overwhelming the Secret Service’s metal detectors. Presidential aides considered canceling the event.

Everything seemed to go fine until after the speech, when Georgian authorities discovered a live hand grenade within 100 feet of the stage. They later determined the device had been thrown at the president but failed to detonate.

“It was a totally dirty crowd,” Steve Atkiss, a former Bush administration official who helped plan the trip, recalled this week. “The president was aware, but he intervened and said, ‘I’m going to go.’ ”

Foreign trips by the U.S. president typically involve hundreds of personnel from the Secret Service, military, State Department and White House, with two months of advance planning — a luxury officials did not have in the case of Mandela’s death on Dec. 5.

Negotiations with foreign governments over security protocols are detailed and demanding. Some countries try to insist that the U.S. president ride in the host country’s motorcade, which is a strict no-no for the Secret Service.

It can be especially challenging at international summits or at an event like the Mandela service, when dozens of nations are involved.

One former Secret Service agent recalled that at the Asia-Pacific Economic Cooperation summit in Peru in 2008, U.S. officials told their hosts that the president would be arriving at a hotel at a certain time and asked that no armed security be present other than Bush’s protective detail. The Russian delegation immediately objected because then-President Dmitry Medvedev was scheduled to arrive minutes later with his own security phalanx, the former agent said.

In the mid-2000s, according to one former U.S. government official, the Secret Service established a program called ARP, requiring that anyone who would come within “arm’s reach of the president” must provide a Social Security number, date of birth and other personal information for a background screening.

But such protocols are difficult abroad, where some do not have verifiable birth certificates or government identification numbers. The State Department’s diplomatic security division conducts background checks on people who will come into contact with the president.

The screenings are also intended to ferret out people whose backgrounds could create a political embarrassment. One former U.S. official recalled an event at an international economic summit in Hawaii in 2011, when Obama was scheduled to meet a group of business executives from 20 countries.

Upon reviewing the names, Obama administration officials determined that one Russian businessman had a “shady background,” though he did not present a security risk, the former official said. White House aides ultimately allowed the man to attend, in part because objecting to his presence might have risked offending the Russian government, the former U.S. official said.

Some speculated that similar diplomatic concerns might have played a part in the preparations at Mandela’s service, where Obama and his aides would be careful not to be too demanding.

“On something like this, the White House would have a checklist and ask the question, ‘Do we have a sign language interpreter for the hearing impaired?’ ” said Atkiss, now with Command Consulting Group. “If they get an answer of yes, they might ask, ‘Has he been certified?’ But when you are a guest of someone and one of hundreds of heads of state, if you ask, you ask very politely, and you might not say, ‘Okay, who is this person and what is his criminal background?’ ”