Secret Service Director Julia Pierson has resigned. (J. Scott Applewhite/AP)

When a dozen Secret Service agents were sent home after a night of partying on a presidential trip to Colombia in 2012, President Obama chalked up the bad behavior to “a couple of knuckleheads.”

When a schizophrenic man pretending to be a sign language interpreter stood on stage with Obama in South Africa in 2013, the White House insisted that the Secret Service “took the precautions necessary to ensure the president’s safety.” And this week, after revelations that an intruder with a knife made it into the White House, a spokesman said Obama has “full confidence in these professionals to do their job.”

At last, on Wednesday afternoon, the president changed his tone. After time and again sounding public notes of support for the Secret Service’s top managers in response to embarrassing accounts of personal misconduct and alarming security breakdowns, the Obama administration finally accepted the resignation of Director Julia Pierson amid bipartisan outrage on Capitol Hill over the agency’s performance.

Homeland Security Secretary Jeh Johnson made the announcement in a written statement, saying that Pierson would be replaced on an acting basis by retired special agent Joseph Clancy.

In part, Obama’s reluctance for so long to publicly criticize Pierson and her predecessor, Mark Sullivan, who left in early 2013, could be attributed to a general reticence by any president to fire Cabinet officials and other top aides, lest the firing be interpreted as an admission of failure for having appointed them in the first place. But former presidential advisers said something else might help explain Obama’s stance in this instance: the deep personal bond and trust that is required between a president and the Secret Service detail charged with protecting him and his family.

The Secret Service is under fire for how it handled an intruder who made his way inside the White House. From a botched investigation into shots fired at the White House to exploits with Colombian prostitutes, here’s a look at other Secret Service scandals. (Jackie Kucinich/The Washington Post)

“This is almost a family affair,” said Ralph Basham, director of the Secret Service from 2003 to 2006. “They live together, work together, travel with each other all the time. This is not just about the director of the service. This is about the men and women willing to lay down their lives to protect him and his family.”

Lead agents on the presidential protective detail ride in the presidential limousine, hold onto the president’s waistband in a crowd, watch over him inside the White House and, on occasion, “get in his face” to dissuade him from straying into unsafe areas, according to former Secret Service officials and presidential aides.

In President George W. Bush’s eight years at the White House, five men served as the special agent in charge of his detail, said his former aides, who could still recall each by name. One, Nick Trotta, had a particularly warm relationship with Bush, who called him “Nicky,” they said.

Aides recalled a presidential trip to an economic summit in Chile in 2004 when local security officials blocked Trotta from accompanying the president into a dinner with more than 1,000 guests. Bush, who had been walking next to his wife, quickly doubled back, grabbed Trotta’s arm and yanked him through the crowd.

The following day, Bush playfully took Trotta’s hand again as he was entering a bilateral meeting to reiterate that they were not to be separated.

“There has to be a respect and trust, and it’s not just a one-way street. It’s got to go both ways,” said Barbara Riggs, the first woman to serve as the Secret Service’s deputy director. She left in 2006 after a 31-year career.

“I’ve served in many administrations where that trust is always critical for the agency,” she said. “The service is not there to be the best friend of the protectee, but because of the nature of our job, you do develop a relationship.”

The White House commented on the resignation of Secret Service Director Julia Pierson on Tuesday, saying Pierson and President Obama agreed that it was in the best interest of the agency that new leadership be appointed. (AP)

That relationship can evolve to overcome initial skepticism. One former agent recalled a stint when he was asked to help provide protection for former Bush adviser Karl Rove. The former agent said he disliked Rove, based on his political views, but “within 24 hours, I loved the guy.”

“He was the only protectee to make sure we had gotten something to eat,” said the former agent, who spoke on the condition of anonymity to describe private interactions. “One day, we were supposed to be done by 9:30 at night, and he suggested we leave an hour before his talk was over so we could go to a restaurant.”

Basham, who had worked in the George H.W. Bush administration, had long-standing personal ties with the younger Bush. For Obama, the protection he received during his historic 2008 campaign — during which the first African American to win the White House inspired an unprecedented number of threats to his safety — helped persuade him to retain Sullivan, who had succeeded Basham in 2006.

Behind the scenes, the president and first lady Michelle Obama have reportedly expressed anger over some of the Secret Service’s failures. The Washington Post reported last week that the agency initially dismissed accounts in November 2011 that a gunman outside the White House perimeter had fired a gun at the complex on a night when one of the Obamas’ daughters, Sasha, was inside. The agency did not determine that bullets had struck near the living quarters until four days later.

The first lady rebuked Sullivan in such a sharp voice that she could be heard through a closed door, according to The Post’s account.

But for seven years, Obama remained publicly supportive of Sullivan, whose tenure included two other well-publicized lapses. A pair of uninvited guests managed to shake Obama’s hand at a White House state dinner in 2009, and a dozen agents were sent home from a presidential trip to Cartagena, Colombia, after being ensnared in a prostitution scandal in 2012.

Sullivan remained on the job until announcing his retirement in February 2013. In a written statement, Obama thanked the director for his service and said he had “led the agency with incredible dedication and integrity.”

Obama replaced him with Pierson, a 30-year veteran who became the first female director — an appointment aimed in part at overcoming a boys’ club reputation at the agency. Pierson, formerly Sullivan’s chief of staff, was thrust into the spotlight in March when news broke that three agents had been sent home from a European summit after one passed out drunk in the hallway of Obama’s hotel.

Pierson, who traveled with Obama aboard Air Force One on that trip, scurried to brief lawmakers on the Hill after they returned.

White House aides emphasized that Obama has expressed concern about the latest security breaches, noting that the president had met twice in the past week with Pierson for private briefings on her ongoing internal investigation.

On Tuesday, White House press secretary Josh Earnest declined to tell reporters what they had talked about in those meetings, other than to say that Pierson did not offer her resignation.

A day later, unable to withstand the outside pressure, she did.