An on-duty Franklin Township police officer was found overdosed on heroin in his patrol vehicle in April, authorities said Friday.

Officer Matthew D. Ellery, 29, of Middlesex Borough, survived the overdose after a fellow officer gave him two doses of Naloxone, an antidote commonly referred to as Narcan that reverses the effects of a drug overdose, Somerset County Prosecutor Michael Robertson said in a statement.

Ellery was working the midnight shift on April 7 when dispatch tried to contact him just after 1 a.m. After he failed to respond, an officer went looking for Ellery and found his patrol vehicle on Bennetts Lane, Robertson said. He did not specify how the officer located Ellery’s vehicle.

Ellery was initially charged on April 15 with just a single, municipal summons of driving while intoxicated, according to a copy of the summons obtained by NJ Advance Media. The case was then transferred to the Somerset County Prosecutor’s Office, which launched a criminal investigation resulting in an additional charge of possession of heroin.

Robertson said Ellery has pleaded guilty to both offenses and will be entered into the Drug Court program. If Ellery fails to finish the program, he could face up to five years in prison. Ellery will also lose his license for seven months and his job as a police officer, a position he’s held since Jan. 22, 2017.

Ellery is scheduled to be sentenced on Aug. 23.

His attorney, Steven Altman of New Brunswick, said, “Matt Ellery is a wonderful young man who has a problem and we’re trying to do what’s needed so he resolves his problem and moves on with his life.”

After NJ Advance Media first published the story on Ellery’s arrest, the department’s top two officials — Chief Richard Grammar and Capt. Gregory Borlan — abruptly announced their retirements. At the same time, the town council adopted a resolution allowing the prosecutor’s office to take over the department and conduct a top-to-bottom review. Franklin has approximately 100 sworn officers.

Have a tip? Tell us. nj.com/tips

Get the latest updates right in your inbox. Subscribe to NJ.com’s newsletters.

Alex Napoliello may be reached at anapoliello@njadvancemedia.com. Follow him on Twitter @alexnapoNJ. Find NJ.com on Facebook.