An FBI task force officer and longtime police detective was fatally shot Wednesday in what officials called an ambush outside of a federal building in Terre Haute.

It's unclear whether Terre Haute Police Detective Greg Ferency was targeted or if the suspect, who was shot by an FBI agent, intended to harm law enforcement in general, the Indianapolis Star reports.

In documents filed today, federal prosecutors said Meehan drove his pickup truck up to the FBI office building, got out of his truck and threw a Molotov cocktail toward the office.

Ferency then walked out of the building and was confronted by Meehan, who was holding a firearm. Meehan raised the firearm and shot Ferency, the government says.

Ferency was able to return fire to defend himself but later died, the government said.

An FBI agent then ran out of the building and engaged Meehan in a gunfight. Despite being shot twice, Meehan got into his truck and fled. He was located at Terre Haute Regional Hospital, where he was treated for his gunshot wounds, the Terre Haute Tribune-Star reports.

Ferency was a beloved and respected member of the department, colleagues said during a news conference Thursday. He was the father of two adult children.

"You'll never meet a finer person," Police Chief Shawn Keen said. “He was an amazing person. I just can’t say that enough.”

The FBI will lead the investigation into the shooting. Special Agent in Charge Paul Keenan said an agent heard gunshots, intervened and shot the suspect, who is in custody at a hospital.

The suspect has been identified as Shane Meehan, 44. He is charged with the premeditated murder of a federal agent. If convicted, he could face up to life in prison, the FBI said in a release.