Department of Justice, File, Associated Press
FILE - This undated file photo provided by the U.S. Department of Justice shows Alcohol Tobacco and Firearms Special Agent John Capano, who died while trying to subdue a suspect in a pharmacy robbery in Seaford, N.Y., Saturday, Dec. 31, 2011. A law enforcement official speaking on the condition of anonymity told The Associated Press on Tuesday, Jan. 3, 2012 that Capano likely was shot by a retired Nassau County police lieutenant who had been down the street at a deli and responded to the robbery along with an off-duty New York police officer. Off-duty and retired law enforcement officers appear to have few protocols to follow when confronting a crime out of uniform, like the apparent friendly fire that left John Capano dead on New Year's Eve.

SEAFORD, N.Y. — As an ATF senior special agent, John Capano traveled the world, from Afghanistan to Iraq, Peru to Paraguay, sharing his expertise investigating the aftermath of bombings.

The 51-year-old father of two died in his hometown in New York on New Year's Eve, killed in a "friendly fire" shooting trying to stop a pharmacy robbery and becoming the first agent for the Bureau of Alcohol, Tobacco, Firearms and Explosives to be killed by gunfire in the line of duty since the raid on a religious cult compound in Waco, Texas, in 1993.

Thousands of law enforcement officials from New York and beyond gathered Friday at a church on Long Island for Capano's funeral. U.S. Attorney General Eric Holder was expected to speak during the service, at St. William the Abbott Church in Seaford.

As the crowd of mourners waited for the service to begin, a dozen children from the parish elementary school stood outside the church in their uniforms, as a sort of honor guard. Mounted officers on horseback also kept a vigil.

Friends of the slain agent said they still couldn't believe what happened.

"I'm still in shock. I'm still trying to figure this out," said ATF agent Gerry O'Sullivan, who knew Capano for 15 years. "John did what most trained law enforcement officers would do. And he did what he thought was best in protecting the public from violent criminals."

Capano, an agent for 23 years, was filling a prescription for his cancer-stricken father Saturday at a pharmacy in Seaford when a man carrying what turned out to be a pellet gun announced a robbery. Capano followed the suspect out the door, where they struggled for Capano's weapon in a skirmish on the sidewalk.

A retired Nassau County police lieutenant who owns a deli three doors down, and an off-duty NYPD officer eating at the deli, raced to the scene. The attorney for the retired lieutenant said in an interview Thursday that his client, 54-year-old Christopher Geraghty, opened fire after a shot whizzed past him, mistakenly thinking that Capano was the robber.

Moments later, the NYPD officer shot and killed the holdup man, later identified as a career criminal with a history of pharmacy robberies.

"He's devastated," attorney Brian Davis said of Geraghty. He said he is aware the Capano family does not blame him for the tragic outcome and has sent a note of condolence, but said the shooting "will be with him for the rest of his life."

Capano, who grew up in Seaford and lived in nearby Massapequa, is survived by his wife and a son and daughter.

A spokesman for the ATF said Thursday that although Capano was not scheduled to be working that day — he was on bereavement leave because his mother had died in mid-December — his death is still considered to have happened in the line of duty. Spokesman Steven Bartholomew said that when Capano took action to stop the robbery in progress, he was acting as an ATF agent.

The shooting was the second friendly fire confrontation in Nassau County in the last year. A Nassau police officer in plainclothes was shot to death in March by a transit authority officer in Massapequa Park.

It was the second deadly holdup in a pharmacy on Long Island in 2011. In June, a gunman killed two store employees and two customers before fleeing with a backpack filled with painkillers.