Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

An on-duty New Jersey police officer who was behind the wheel of his patrol car when he was found overdosed on heroin in April has lost his job, authorities said Friday.

Matthew D. Ellery, 29, of Middlesex, was sworn in as a police officer with the Franklin Township Police Department in August 2016, according to Lt. Philip Rizzo, a department spokesman. Ellery was assigned to the patrol division.

Matthew Ellery, a on-duty police officer, overdosed on heroin inside his police vehicle and nearly died from an overdose in New Jersey. Somerset County Prosecutor's Office

Shortly after 1 a.m. on April 7, Ellery was working when dispatch attempted to reach him via police radio, according to the Somerset County Prosecutor’s Office. After he failed to respond, an officer went looking for him at his last known location and found him unresponsive in the driver's seat of his patrol car that was parked in the driveway of a business.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The responding officer, who is also an emergency medical technician, determined that Ellery was experiencing an opiate overdose and gave him two doses of Naloxone, a medication commonly referred to as Narcan that reverses opioid overdoses.

Ellery pleaded guilty in superior court Friday to possession of heroin and driving while intoxicated.

As part of his plea deal, Ellery will forfeit his job as a police officer. He will also lose his driver's license for seven months.

Ellery will avoid jail or prison by applying to the Somerset County Drug Court program. If he does not finish the program, he could face up to five years in prison.

His attorney, Steven Altman, could not immediately be reached for comment.

Ellery is scheduled to be sentenced in Superior Court in Somerville on Aug. 23.