A former Philadelphia police officer admitted Friday in federal court to sexually assaulting a woman while on duty three years ago and threatening her in his squad car with his service weapon and a knife.

Thomas O’Neill, a 24-year veteran of the force, pleaded guilty to one count of deprivation of rights as part of a deal struck with prosecutors that would limit his sentence to one year behind bars.

Ultimately, though, it will be up to U.S. District Judge Juan R. Sanchez to decide whether to accept the terms of that agreement at a sentencing scheduled for May.

During a brief hearing Friday, O’Neill, 53, blamed alcoholism for clouding his judgment.

“I recognized that I was an alcoholic, and it contributed to the actions of that day,” he said, adding later: “I’ve thought carefully about this decision, and it is my decision” to plead guilty.

O’Neill’s accuser — whose name is being withheld because she was the victim of a sexual assault — came forward within days of the July 3, 2016, attack.

She told police Internal Affairs and later the FBI that she had met O’Neill when he responded to her apartment building during a robbery call several days earlier. When he spotted her later on her bike, he pulled up his squad car and ordered her to get inside.

O’Neill drove the woman to an isolated spot in Rhawnhurst near Northeast High School and sexually assaulted her inside and outside the vehicle for nearly an hour, she said. For much of that time, she alleged, O’Neill had his service weapon pressed against her inner thigh and forced her to touch it.

In a lawsuit filed in 2016, the accuser, a white woman in her mid-30s, also alleged that O’Neill, who also is white, made racially charged comments, saying he fantasized about beating, raping and “shooting a n—” in the head. He also described having sex with other women he had picked up in his squad car.

“She did not feel she could refuse to get into [O’Neill’s] patrol vehicle,” Assistant U.S. Attorney Michelle Morgan said.

In court Friday, O’Neill sat silently next to his lawyer as the prosecutor recounted the details of his crime — one compounded by the amount of evidence he left behind.

Parts of the assault were caught on security camera footage, and the shorts the woman wore on the night of the assault tested positive for O’Neill’s DNA.

His accuser also provided text messages she received days after the attack from a cell phone number that traced back to O’Neill.

“It’s sexy cop,” he said in one message. Moments later he sent her another, asking her to send him naked photos of herself.

“I want you,” it read. “Don’t want to scare you.”

After the department began investigating, O’Neill abruptly retired in September 2016.

He is almost certain to lose his retirement benefits and pension as a result of his guilty plea.

His admissions Friday are also likely to help an ongoing civil case that his accuser has lodged against him and the Police Department.

“We are pleased that he pleaded guilty so we can put this behind us,” said the woman’s lawyer, Gregg L. Zeff. “We look forward to the civil trial against the City of Philadelphia, where we think there will be more wrongdoing exposed.”

O’Neill could have faced up to 10 years in prison had he not agreed to plead guilty Friday and accept a one-year term of incarceration, said his lawyer, Lloyd Long III.

“Mr. O’Neill resigned from his position as a police officer and accepted his responsibility for the conduct that led to these charges today,” Long said.

If the judge rejects the agreement between O’Neill and prosecutors in May, the former officer would be able to withdraw his plea and take his case to trial.

CORRECTION: An earlier version of this story incorrectly reported the race of O’Neill’s accuser. She is white.