The 40-year-old man from a small town in western Pennsylvania met the 14-year-old girl online, prosecutors said. He sent lewd pictures to her and solicited sexual contact and made plans to meet her.

On Friday, the man, Michael W. Diebold, showed up at the place where he and the girl had agreed to get together.

By day, Mr. Diebold is the chief of the Leechburg Police Department, where he oversees two full-time and 15 part-time officers. His department helps protect the 2,000-person borough, about 25 miles northeast of Pittsburgh.

And as it turned out, the person Chief Diebold planned to meet on Friday was an undercover member of law enforcement — not the teenage girl he had hoped to find, prosecutors said.