The south side of the White House is shown near where a bullet struck a window in the residential quarters Nov. 11, 2011. (Win McNamee/Getty Images)

The Secret Service began struggling to carry out its most basic duties after Congress and the George W. Bush administration expanded the elite law enforcement agency’s mission in the wake of the Sept. 11, 2001, terrorist attacks.

According to government documents and interviews with dozens of current and former officials, the recent string of security lapses at the White House resulted from a combination of tight budgets, bureaucratic battles and rapidly growing demands on the agency that have persisted through the Bush and Obama administrations in the 13 years since the attacks. At the same time, the Secret Service was hit by a wave of early retirements that eliminated a generation of experienced staff members and left the agency in a weakened state just as its duties were growing.

The agency assumed new responsibilities monitoring crowds at an increasing number of major sporting events and other large gatherings seen as potential targets for terrorists. A new anti-terrorism law gave the agency a leading role in tracking cyberthreats against U.S. financial systems. And Bush expanded the circle of people granted round-the-clock protection to include the president’s and vice president’s extended family and some White House aides — an expansion that has been largely maintained under President Obama.

Where the Secret Service had been a gem of the Treasury Department for more than a century, its post-9/11 transfer to the sprawling new Department of Homeland Security suddenly forced it to compete for money and attention with bigger and higher-profile agencies focused on immigration and airport security.

The changes set in motion during that critical period after 2001 led to a slow, steady slide in quality, leaving an agency that, according to a DHS report released on Dec. 18, is “stretched to and, in many cases, beyond its limits.”

In the aftermath of the 9/11 terrorist attacks, the Secret Service struggled with expanded duties, more complex security threats and largely flat budgets followed by cuts.

“We are not the Super Bowl team we once were,” Dan Emmett, a former Secret Service supervisor, said in a recent interview with The Washington Post.

When the attacks came in 2001, the Secret Service was seen as a model organization, revered for its aura of invincibility. Its stoic agents with their earpieces and dark sunglasses were immortalized in Hollywood movies, while the agency boasted a zero-error rate after the lessons learned from the assassination of President John F. Kennedy in 1963 and the shooting of President Ronald Reagan in 1981. In addition to its well-known duties protecting the country’s leaders, the agency was also carrying out a longtime dual mission of combating counterfeiters.

The day before the attacks, Secret Service details were safeguarding 18 people, including the president, the vice president and their immediate families, as well as former presidents and their spouses. Presidents have the power to expand the number of people under Secret Service protection, as President Bill Clinton temporarily did in the late 1990s amid growing concerns about al-Qaeda.

Immediately after the attacks, temporary details were mobilized for Bush’s extended family, including his grown siblings. Later, with the country at war in Afghanistan, the agency provided details for Vice President Dick Cheney’s grandchildren in addition to those for his adult daughters, Liz and Mary.

With that, the standard was set. By late 2003, Secret Service details were assigned to 29 people. Currently, the agency protects 27 people, including Vice President Biden’s five grandchildren, ranging from middle-school to college age, and senior White House adviser Valerie Jarrett.

The details create an added strain, as the service must field a team of anywhere from two to six agents to protect a person, usually with two to three rotating shifts per day.

The job of protecting the president was also growing more difficult in the post-9/11 world. The agency had to prepare for a rapidly expanding list of potential attacks to ward off — including improvised explosives, shrapnel truck bombs, and biological and chemical assaults.

From a botched investigation into shots fired at the White House to exploits with Colombian prostitutes, here’s a look at recent Secret Service scandals. (Jackie Kucinich/The Washington Post)

But resources remained largely flat, forcing agents to work longer hours and spend extended stretches­ on the road. For years, hard work helped keep the agency’s turmoil from showing.

Inside DHS, the 6,200-member Secret Service was dwarfed by the new Transportation Security Administration and the rapidly growing U.S. Customs and Border Protection, each with more than 50,000 employees.

DHS officials were focused on addressing high-profile security concerns, and hundreds of millions of dollars were directed to anti-terrorism programs. But the Secret Service’s mission did not engender the same sense of urgency, according to people familiar with internal deliberations.

Tom Ridge, named by Bush to head DHS after its formation, said the terrorist attacks understandably reshaped priorities, although he said the Secret Service received the funding it needed.

“The entire focus of the nation shifted after 9/11, and all federal agencies had to adjust to the new realities,” Ridge said recently through a spokesman. “That said, the Secret Service, because of its protective mission and direct ties to the White House, never suffered from a lack of resources­ to carry out their critical responsibilities during my time at DHS.”

Andrew Card, the White House chief of staff at the time, said he intervened several times to fight off proposed cuts to the Secret Service’s budget. But Congress and DHS officials did not always view some of the agency’s initiatives as a top priority, he said.

“They’d say, ‘We need X millions of dollars to address this threat,’ ” Card recalled, “Somebody asks, ‘What’s the chance of that happening?’ The answer is maybe 2 percent. To the Secret Service agent, it doesn’t matter. . . . If it happens, it’s 100 percent.”

Chris Cummiskey, a former Obama DHS official who retired this fall, said he saw the Secret Service struggle — and suffer financially — from “organizational turmoil” stemming from its presence in DHS.

Cummiskey said the agency pushed for money in some areas — such as enhancing protective counter­measures at the White House and updating communications systems — but got far less than it sought.

“There was a competition for dollars in an increasingly finite budget environment,” he said. “All of a sudden, there was high premium placed on justification.”

Don Mihalek, a New York field agent who is the national representative for Secret Service agents in their law enforcement association, said the agency’s mission and “operational tempo” increased “exponentially” after the 2001 attacks.

“But the budget has never been commensurate with that,” he said.

As it happened, just as the Secret Service was facing those new bureaucratic challenges, it was in an especially weakened position — reeling from the early retirement of 925 senior agents from 1993 to 2002.

Under a 1950s-era program, Congress had given most agents and officers the same generous benefits as D.C. police received and allowed them to retire after 20 years of service. In 1983, Congress replaced that program with a less generous federal retirement plan. Most of the last agents covered under the old program reached their 20-year mark in the years leading to 9/11.

A report by the federal Office of Personnel Management in 2004 noted the potential ill effects of the loss of so many seasoned agents, saying that the agency “was losing these highly experienced law enforcement officers at a point in their careers when they are still capable of effectively serving.”

One of the earliest signs that the Secret Service was suffering from the strain came in May 2005, when the agency and local officers were unable to control a huge crowd entering a plaza in Tblisi, Georgia, to hear Bush deliver a pro-democracy speech. Thousands got past magnetometers used to screen for weapons.

Minutes after Bush began speaking, a protester threw a live grenade that landed 100 feet from the president. A defect kept the grenade from exploding, but the FBI concluded that shrapnel could have hit and injured Bush if it had detonated.

The election of Barack Obama in 2008 brought new challenges, as the agency saw an escalation of threats against the country’s first black president.

After a pair of aspiring reality-TV stars managed to talk their way into a White House state dinner in 2009, then-Secret Service Director Mark J. Sullivan initiated a broad review of vulnerabilities in the security net around the White House. Sullivan had previously complained to senior DHS leaders that most of his proposed technology upgrades and counter­measures were cut, former department officials said. The review team made about 130 recommendations, which were compiled in a classified report.

The review prompted DHS to spend about $80 million over the next several years to, among other things, improve screening for chemical and biological threats and upgrade communications at the White House complex. But some of the vulnerabilities cited in the report, concerning both the security of the White House and the safety of the president during travel, have not been fully addressed, according to people familiar with the report. In one case, the report highlighted the need to create a new security perimeter for the White House to address the insufficiency of the fence to stop intruders.

“We kept fighting, and we increased funding with major investments in cybersecurity, technology and White House counter­measures,” Sullivan told The Post in an interview this month. “Although we didn’t always get what we wanted, every single time we had knowledge of how to better protect our protectees, we fought hard for funding.”

As budget battles began to dominate Washington after the tea party wave of 2010 and lawmakers and the Obama administration pursued ways to slash the deficit, the Secret Service suffered cuts along with other federal agencies. The service was then forced to deal with problems that became public embarrassments. It failed to properly investigate a 2011 shooting targeting the White House, and agents were recalled from a 2012 summit that Obama attended in Colombia after being caught hiring prostitutes.

The Secret Service’s budget was cut — with the onset of sequestration — from $1.6 billion in 2012 to $1.5 billion in 2013. Relying on attrition, the agency cut its total staff by nearly 300, to 6,480, its records show.

The impact was deeply felt in the Uniformed Division, the arm of the Secret Service that protects the White House complex. Its officers were so frequently called in to work on their days off that most training was canceled to keep posts covered. The agency estimated that it needed 1,420 officers in the division to properly do its job, but it had 100 fewer than that.

In 2012 and 2013, agency officials canceled all but three of the summer academy classes­ that train new officer candidates, in part due to budget constraints. So when a steady stream of weary officers resigned during that period, the agency ran out of academy graduates to fill the spots.

To get the posts covered, the agency flew higher-paid agents in from field offices around the country to do temporary rotations. It had to pay for the agents’ travel, lodging, food and other ­expenses.

The toll on the Uniformed Division was cited as a major problem in the DHS report released this month. The panel that conducted the review called for adding 200 officers. It also assailed the Secret Service’s leadership for not knowing the actual cost for properly protecting the president and for instead making ballpark guesses on how much Congress would approve.

“[N]o one has really looked at how much the mission, done right, actually costs,” the panel said of the service’s budgeting process.

Rep. Bennie Thompson (Miss.), the ranking Democrat on the House Homeland Security Committee, said in an interview that he was disturbed by the service’s shoestring approach.

“You feel the commander in chief deserves the best security protocols known to man. There’s no skimping, there’s no talk about people working a lot of overtime, all this foolishness,” he said.

While not filling officer positions last year, the agency spent about $1 million on a project sought by then-Director Julia Pierson: upgrading a “Director’s Crisis Center” adjoining her executive suite. The new center is a smaller, near-replica of the Joint Operations Center on another floor of the Secret Service’s downtown Washington headquarters.

Pierson defended the project at a House hearing in September on the day before she resigned, saying managers “need to have instant information for us to be able to make informed decisions.”

Meanwhile, morale among agents and officers has been sinking amid a growing view that the agency was being led by an insular clique resistant to oversight and eager to promote yes men rather than independent thinkers.

A 2013 survey of Secret Service employees found what it called a “noteworthy” distrust of senior managers among the rank and file. Nearly 1 in 4 — 587 out of 2,575 — said they believed that top managers were not held responsible for their own misconduct. And 1 in 5 said they felt management tolerated misconduct, according to the electronic survey, conducted by the DHS’s inspector general’s office.

In addition, employees noted 318 incidents in which they witnessed colleagues engaged in misconduct that could threaten security, such as drunkenness or solicitation of prostitutes. In 80 percent of the incidents, they did not report the behavior — the most prevalent reason cited was they did not believe that management supported employees reporting such behavior.

Joseph P. Clancy, a former leader of Obama’s protective detail who assumed the role of acting Secret Service director when Pierson resigned, told lawmakers last month that a desire to fix the widespread distrust of management was “an integral part of why I agreed to return.”

Members of Congress are also distressed about the ill will that many agents and officers feel toward their bosses.

Rep. Elijah E. Cummings (Md.), the ranking Democrat on the House Oversight and Government Reform Committee, said in an interview that a “culture here of mediocrity, complacency and inefficiency” has resulted largely from the fear of agents to speak up. “They fear nothing will happen. They fear they’ll be retaliated against,” he said.

Secret Service officials say the agency, which protected more than 6,000 venues in fiscal 2014, is learning from its mistakes. “There is no question that today’s security environment presents distinct challenges,” agency spokesman Brian Leary said. “Our mission is one that requires constant vigilance and commitment from each of our employees, at all times.”

Still, to many who have long studied the Secret Service, the agency’s internal problems set the stage for a string of miscues that gained widespread public attention this year.

An internal review of the Sept. 19 incident in which a knife-wielding man was able to leap the White House fence and race through the building found that several officers on duty had never been trained in the types of force to use to stop an intruder who had entered the front door. Many officers had been on the job less than a year and were uncertain about their specific responsibilities in such a case. Some were confused about how the White House radio communications system worked in a crisis.

Cummiskey, the former DHS official, said it’s easy to connect the budget dots to this and other recent security lapses. “They’ve got fewer people and more demands, so it makes it harder for them to cover all the ground,” he said.

Rep. Jason Chaffetz (R-Utah), the incoming chairman of the House Oversight Committee, said the Secret Service has rarely had to answer hard questions from Congress or oversight groups and has repeatedly cited a need for secrecy to do its job.

“I don’t think the Secret Service has been held accountable for the last 15 years,” Chaffetz said.

Thompson said the agency’s recent missteps may have finally triggered a meaningful reassessment of whether the Secret Service can keep the president safe.

“Finally, people are acknowledging that obviously there has to be something wrong inside this agency,” he said. “You can’t gloss over what has occurred.”

Alice Crites contributed to this report.