A former Philadelphia police narcotics officer who spent more than two decades on the force was sentenced Monday to 18 months in federal prison, capping a stunning downfall that involved his trading drugs for sexual favors with two women, one of whom later, on the Pennsylvania Turnpike, crashed her car while driving high in a wreck that killed a 90-year-old passenger.

Stanley Davis, 50, spent much of the hour-long sentencing hearing with his head in his hands, occasionally wiping away tears, as family members addressed U.S. District Judge R. Barclay Surrick, and talked about Davis' love of the police force and the remorse he has felt since pleading guilty.

The judge called Davis' behavior "outrageous" and said that by using his position of power to gratify his impulses, Davis added "fuel to [the] fire" for those who question or criticize the police.

"The faith in the police department was unquestionably compromised here," Surrick said.

Davis abruptly retired last year after a 21-year career in which he earned dozens of awards and commendations, according to court documents filed by his attorneys. Before stepping down, Davis had been assigned to an FBI narcotics squad and frequently worked in and around Kensington, the neighborhood hit hardest by the city's opioid crisis.

It was there in 2016 that Davis met two drug-using women and began exchanging sexually charged text messages with them, according to court records. Before long, Davis and the women began engaging in sexual trysts in New Jersey motel rooms and inside his police vehicle. The encounters sometimes ended with Davis providing the women with drugs, including heroin and cocaine, the records say.

Investigators caught on to the arrangement after one of the women, Rosie Dorothy Forsyth, crashed her car in November 2016 on the Pennsylvania Turnpike in West Pikeland Township. Forsyth's passenger, Thelma Frey, died from her injuries six days later, prompting Chester County prosecutors to charge Forsyth in connection with the death. Forsyth then told police about her relationship with Davis.

Last August, Davis pleaded guilty to federal drug distribution charges related to his interactions with Forsyth and the other woman, who is not named in court documents.

But in a sentencing memo filed this year, prosecutors, led by Assistant U.S. Attorney Robert J. Livermore, alleged that Davis had behaved similarly with at least four other women in the past, and that he had exchanged text messages "with more women than the FBI agents were able to count."

"In truth," prosecutors wrote in their memo, "Davis was a sexual predator."

Family members on Monday, however, universally described Davis as a good cop and caring father who lost his way for reasons that remain a mystery, even to Davis himself. Jack McMahon, his lawyer, said: "It's been a living hell and torment for him."

His cousin Barbara Cocco said she thought Davis' behavior could have been spurred by his undercover work, causing him to lose sight of the distinction between his life and the role he was expected to play on the job.

Besides costing him his job and pension, his crimes also led to a second divorce, his attorney wrote in court filings.

Davis, in a one-sentence address to Surrick, said: "I'm just sorry for my actions and everybody I let down."

The judge ordered Davis to turn himself in to a federal prison on May 29. He was also fined $4,000 and will have three years of supervised release after leaving prison.