The former president of Radnor Township’s Board of Commissioners was sentenced Tuesday to 12 years and 7 months in federal prison in the child pornography case that ended his political career and shook the Main Line community that he was elected to serve.

Addressing the court, Philip Ahr, 68, apologized to his victims, his family, and his constituents, and stressed the treatment and self-recrimination he has undergone during the last 18 months he has spent behind bars.

“When I was committing these crimes, I was sick and did not realize the harm I was causing,” he said. “My actions helped to support an industry that preys upon the most vulnerable in our society.”

But while U.S. District Judge Michael M. Baylson acknowledged the former elected official and marketing executive’s efforts at rehabilitation, he said that harsh prison sentences were the only way to threaten a black-market industry that has victimized thousands of children.

“This is an addiction, but not an addiction that calls out for treatment,” the judge said. “This is an addiction that calls out for punishment. The only way that this is going to stop is if there is a stiff punishment for those who consume it.”

Ahr’s sentencing comes two years after Delaware County authorities showed up at his Bryn Mawr home on a tip from the National Center for Missing and Exploited Children that a Yahoo Messenger account associated with him had been flagged for trafficking in illicit images of children.

Ahr at first minimized his crimes, saying he had been “sexting” with an unknown person online who sent him images of children that he knew to be illegal. Then, as soon as investigators left, he took steps to delete all transcripts of his online conversations in chat rooms with names like “pedomoms” and “little boy sex chats” and deleted a Dropbox account that contained additional illegal material.

By the time he was charged and resigned his seat in November 2017, authorities had uncovered thousands of pornographic images of children on devices under Ahr’s control, including a computer issued by his employer, Progressive Business Publications, and an iPad that Ahr had been given by Radnor Township for government business. He also kept spreadsheet directories of thousands of child porn websites and disguised them as files for mundane data keeping.

Some of those images depicted abuse of children as young as 2 years old. Others involved sadomasochistic sex acts between children and animals.

But worse, said Assistant U.S. Attorney Michelle Rotella, were the hundreds of transcripts investigators eventually uncovered from chat rooms where Ahr, using the screen name “DaddyXX,” met with like-minded pedophiles.

There, he boasted about sexually abusing his own relatives when they were younger and quipped, according to court filings: “Nice memories, though they don’t remember it."

He spoke of being turned on by scared children — and directed people on the other end of the chats on how to abuse their own family members live for his gratification.

“Crying makes it hotter,” he said in one transcript quoted in prosecution filings.

“These were some of the most vile chats that I have ever read,” said Rotella, an experienced child sex crimes prosecutor. “His communications were violent. They were wicked. They were depraved."

Ahr, a married father of adult children who was first elected as a Democrat to the commissioners’ board in 2016, sat silently through much of Tuesday’s hearing. His conduct was discussed in explicit detail in front of a crowd of supporters including his wife; his former boss; his priest; and Radnor Township Commissioner John C. Nagle, a former colleague on the board.

“I just think he’s been treated so unfairly,” Nagle was overheard telling another observer at one point before abruptly leaving during the government’s presentation. “Asked what he meant after the hearing, he responded to a reporter’s emailed questions by saying he was in a meeting and could not talk until Wednesday.

When it was time for Ahr to address the court, he did not shy away from acknowledging his depravity but insisted it was all in the past. He decided to plead guilty shortly after he was indicted on federal charges and insisted before Tuesday’s hearing on reading every letter submitted to the court by victims depicted in the porn he viewed.

One, according to court filings, read: “Each time someone downloads pictures of me being raped and abused, I picture some pervert enjoying self-gratifying pleasure from my pain. Each victim notification envelope represents someone else who either momentarily or sexually profits from me.”

Those messages, Ahr’s lawyer Stephen P. Patrizio said, brought his client to tears. And Ahr maintained Tuesday that the thought of viewing any pornography is now “abhorrent to me.”

The judge cited Ahr’s commitment to treatment, his past civic-mindedness and his advanced age in agreeing to cut the ex-commissioner a break from the nearly 20-year prison term that prosecutors had sought. But the sentence ultimately imposed was still nearly three times the defense request to limit his incarceration to the five-year mandatory minimum required under federal law.

In addition to his prison term, Ahr was ordered to pay $43,000 in restitution and serve 10 years’ probation upon his release. He will have to register as a sex offender.