Members of the FBI's Hostage Rescue Team demonstrate close quarter battle training at the Tactical Firearms Training Center on Tuesday April 08, 2014 in Quantico, VA. (Matt McClain/The Washington Post)

When U.S. Special Operations forces raided several houses in the Iraqi city of Ramadi in March 2006, two Army Rangers were killed when gunfire erupted on the ground floor of one home. A third member of the team was knocked unconscious and shredded by ball bearings when a teenage insurgent detonated a suicide vest.

In a review of the nighttime strike for a relative of one of the dead Rangers, military officials sketched out the sequence of events using small dots to chart the soldiers’ movements. Who, the relative asked, was this man — the one represented by a blue dot and nearly killed by the suicide bomber?

After some hesi­ta­tion, the military briefers answered with three letters: FBI.

The FBI’s transformation from a crime-fighting agency to a counterterrorism organization in the wake of the Sept. 11, 2001, attacks has been well documented. Less widely known has been the bureau’s role in secret operations against al-Qaeda and its affiliates in Iraq and Afghanistan, among other locations around the world.

With the war in Afghanistan ending, FBI officials have become more willing to discuss a little-known alliance between the bureau and the Joint Special Operations Command (JSOC) that allowed agents to participate in hundreds of raids in Iraq and Afghanistan.

The relationship benefited both sides. JSOC used the FBI’s expertise in exploiting digital media and other materials to locate insurgents and detect plots, including any against the United States. The bureau’s agents, in turn, could preserve evidence and maintain a chain of custody should any suspect be transferred to the United States for trial.

The FBI’s presence on the far edge of military operations was not universally embraced, according to current and former officials familiar with the bureau’s role. As agents found themselves in firefights, some in the bureau expressed uneasiness about a domestic law enforcement agency stationing its personnel on battlefields.

The wounded agent in Iraq was Jay Tabb, a longtime member of the bureau’s Hostage and Rescue Team (HRT) who was embedded with the Rangers when they descended on Ramadi in Black Hawks and Chinooks. Tabb, who now leads the HRT, also had been wounded just months earlier in another high-risk operation.

James Davis, the FBI’s legal attache in Baghdad in 2007 and 2008, said people “questioned whether this was our mission. The concern was somebody was going to get killed.”

Davis said FBI agents were regularly involved in shootings — sometimes fighting side by side with the military to hold off insurgent assaults.

“It wasn’t weekly but it wouldn’t be uncommon to see one a month,” he said. “It’s amazing that never happened, that we never lost anybody.”

Others considered it a natural evolution for the FBI — and one consistent with its mission.

“There were definitely some voices that felt we shouldn’t be doing this — period,” said former FBI deputy director Sean Joyce, one of a host of current and former officials who are reflecting on the shift as U.S. forces wind down their combat mission in Afghanistan. “That wasn’t the director’s or my feeling on it. We thought prevention begins outside of the U.S.”

‘Not commandos’

In 1972, Palestinian terrorists killed 11 Israeli athletes at the Munich Olympics, exposing the woeful inadequacy of the German police when faced with committed hostage-takers. The attack jolted other countries into examining their counterterrorism capabilities. The FBI realized its response would have been little better than that of the Germans.

It took more than a decade for the United States to stand up an elite anti-terrorism unit. The FBI’s Hostage Rescue Team was created in 1983, just before the Los Angeles Olympics.

At Fort Bragg, N.C., home to the Army’s Special Operations Command, Delta Force operators trained the agents, teaching them how to breach buildings and engage in close-quarter fighting, said Danny Coulson, who commanded the first HRT.

The team’s mission was largely domestic, although it did participate in select operations to arrest fugitives overseas, known in FBI slang as a “habeas grab.” In 1987, for instance, along with the CIA, agents lured a man suspected in an airline hijacking to a yacht off the coast of Lebanon and arrested him.

In 1989, a large HRT flew to St. Croix, Virgin Islands, to reestablish order after Hurricane Hugo. That same year, at the military’s request, it briefly deployed to Panama before the U.S. invasion.

The bureau continued to deepen its ties with the military, training with the Navy SEALs at the Naval Special Warfare Development Group, based in Dam Neck, Va., and agents completed the diving phase of SEAL training in Coronado, Calif.

Sometimes lines blurred between the HRT and the military. During the 1993 botched assault on the Branch Davidian compound in Waco, Tex., three Delta Force operators were on hand to advise. Waco, along with a fiasco the prior year at a white separatist compound at Ruby Ridge, Idaho, put the FBI on the defensive.

“The members of HRT are not commandos,” then-FBI Director Louis J. Freeh told lawmakers in 1995. “They are special agents of the FBI. Their goal has always been to save lives.”

After Sept. 11, the bureau took on a more aggressive posture.

In early 2003, two senior FBI counterterrorism officials traveled to Afghanistan to meet with the Joint Special Operations Command’s deputy commander at Bagram air base. The commander wanted agents with experience hunting fugitives and HRT training so they could easily integrate with JSOC forces.

“What JSOC realized was their networks were similar to the way the FBI went after organized crime,” said James Yacone, an assistant FBI director who joined the HRT in 1997 and later commanded it.

The pace of activity in Afghanistan was slow at first. An FBI official said there was less than a handful of HRT deployments to Afghanistan in those early months; the units primarily worked with the SEALs as they hunted top al-Qaeda targets.

“There was a lot of sitting around,” the official said.

The tempo quickened with the U.S.-led invasion of Iraq in 2003. At first, the HRT’s mission was mainly to protect other FBI agents when they left the Green Zone, former FBI officials said.

Then-Lt. Gen. Stanley A. McChrystal gradually pushed the agency to help the military collect evidence and conduct interviews during raids.

“As our effort expanded and . . . became faster and more complex, we felt the FBI’s expertise in both sensitive site exploitation and interrogations would be helpful — and they were,” a former U.S. military official said.

In 2005, all of the HRT members in Iraq began to work under JSOC. At one point, up to 12 agents were operating in the country, nearly a tenth of the unit’s shooters.

The FBI’s role raised thorny questions about the bureau’s rules of engagement and whether its deadly-force policy should be modified for agents in war zones.

“There was hand-wringing,” Yacone said. “These were absolutely appropriate legal questions to be asked and answered.”

Ultimately, the FBI decided that no change was necessary. Team members “were not there to be door kickers. They didn’t need to be in the stack,” Yacone said.

But the FBI’s alliance with JSOC continued to deepen. HRT members didn’t have to get approval to go on raids, and FBI agents saw combat night after night in the hunt for targets.

In 2008, with the FBI involved in frequent firefights, the bureau began taking a harder look at these engagements, seeking input from the military to make sure, in police terms, that each time an agent fired it was a “good shoot,” former FBI officials said.

‘Mission had changed’

Members of the FBI’s HRT unit left Iraq as the United States pulled out its forces. The bureau also began to reconsider its involvement in Afghanistan after nearly a dozen firefights involving agents embedded with the military and the wounding of an agent in Logar province in June 2010.

JSOC had shifted priorities, Joyce said, targeting Taliban and other local insurgents who were not necessarily plotting against the United States. Moreover, the number of al-Qaeda operatives in Afghanistan had plummeted to fewer than 100, and many of its operatives were across the border, in Pakistan, where the military could not operate.

The FBI drew down in 2010 despite pleas from JSOC to stay.

“Our focus was al-Qaeda and threats to the homeland,” Joyce said. “The mission had changed.”

FBI-JSOC operations continue in other parts of the world. When Navy SEALs raided a yacht in the Gulf of Aden that Somali pirates had hijacked in 2011, an HRT agent followed behind them. After a brief shootout, the SEALs managed to take control of the yacht.

Two years later, in October 2013, an FBI agent with the HRT was with the SEALs when they stormed a beachfront compound in Somalia in pursuit of a suspect in the Nairobi mall attack that had killed dozens.

That same weekend, U.S. commandos sneaked into Tripoli, Libya, and apprehended a suspected al-Qaeda terrorist named Nazih Abdul-Hamed al-Ruqai as he returned home in his car after morning prayers. He was whisked to a Navy ship in the Mediterranean and eventually to New York City for prosecution in federal court.

Word quickly leaked that Delta Force had conducted the operation. But the six Delta operators had help. Two FBI agents were part of the team that morning on the streets of Tripoli.