WASHINGTON — The F.B.I. had a job offer for Nick Young, a veteran Washington transit officer: Become an undercover informant for the bureau and gather information at local mosques on fellow Muslims who might pose a terrorism threat.

The clandestine work would be “a lot sexier” than his current job, Mr. Young remembered an agent named Ryan telling him. And it could pay him a lot of money if the intelligence was good.

Mr. Young turned him down. But it would not be the last time he would see the F.B.I. agent.

Last August, five years later, Mr. Young was summoned to the headquarters of the transit agency, Metro, where Ryan and other agents were waiting for him. “You probably don’t recognize me, do you?” Ryan, whose beard was now thicker, asked him. “Oh, I recognize you,” Mr. Young said. This time, the agent handcuffed Mr. Young on a charge of supporting the Islamic State — a case built, in a twist, by an informant who posed as a would-be terrorist fighter.

The prosecution of Mr. Young, the only law enforcement officer among more than 100 Americans who have been accused of helping the Islamic State, offers a revealing look at the F.B.I.’s shadowy cat-and-mouse efforts to identify possible Islamic extremists. President Trump has vowed to intensify the effort as part of a campaign to “annihilate” the militant group.