A police detective who had investigated online crimes against children killed himself Tuesday, moments before police could charge him with having inappropriate contact with two young teens.

David Edward Abbott, 39, of Gainesville, Virginia, was a Manassas City detective. He had served on the Northern Virginia-Washington, D.C. Internet Crimes Against Children Task Force.

Police tried to serve him with warrants Tuesday, but he refused to surrender, authorities said. Believing Abbott was armed, police began to evacuate nearby homes.

At about 7 a.m., as detectives spoke to Abbott, he pulled out a gun and shot himself, police said.

Abbott was pronounced dead at the scene, a townhome he shared with his sister in Gainesville, Va.

The search and arrest warrants were for having inappropriate conduct with two victims while Abbott was a Prince William youth hockey coach. He was to be charged with two counts of taking indecent liberties and two counts of using a communications device to solicit sexual offenses.

Police said Abbott made contact with the first victim when the boy was 11 years old.

According to police, Abbott solicited sex acts over phone, by text and through social media and email, police said. He also had face-to-face contact with the boy, police said.

During the investigation, police discovered a second victim, whom Abbott contacted when the boy was 13 years old.

The hockey club said it was working with parents and players to make sure that they got any support that they needed.

Manassas police called the day a tragic one, and issued a statement, saying, "In spite of these recent developments regarding the serious allegations against him, we are grateful for the contributions detective Abbott made during his time with Manassas City Police."

In 2014, Abbott was the detective in a high-profile case in which a 17-year-old Manassas teen was sentenced for sending explicit texts to his 15-year-old girlfriend.

At one point, police had sought to take a photo of the 17-year-old's genitals, including some in an aroused state, to make the case.

The request led to protests from the 17-year-old's lawyer, who said at one point, "Who does this? It's just crazy."

Abbott sued the lawyer for defamation.