SOMERVILLE, N.J. - A New Jersey police officer has pleaded guilty to possession of heroin and driving while intoxicated while on duty in April.

Matthew D. Ellery, 29, of Franklin Township, pleaded guilty Friday before Somerset County Superior Court Judge Kevin M. Shanahan to an accusation of possession of a controlled dangerous substance, heroin, a third degree crime, and a summons related to driving while intoxicated, prosecutors said in a release.

Ellery pleaded guilty as part of a plea agreement in which he will apply for admission into the five year Somerset County Drug Court Program, with an alternative sentence in the range of three to five years in New Jersey State Prison if he fails to successfully complete the drug court program; a seven month suspension of his driver’s license, associated fines and penalties, and the loss of his job as a Franklin Township police officer.

His sentencing is scheduled for Aug. 23, the release states.

State records show Ellery earned $45,542 as a police officer and enrolled in the Police and Firemen's Retirement System in September 2016. He was hired by the police department on Aug. 22, 2016, according to the prosecutor's office.

Ellery’s accusation and guilty plea stem from an on-duty incident at 1:08 a.m. April 7, in which Franklin Township Police Department communications tried to reach him by radio but he failed to respond, the release says.

More:Ex-Mets pitcher Dwight Gooden arrested for cocaine possession last month in New Jersey

Another Franklin Township Police officer was dispatched to Ellery's location and found his patrol car parked in the driveway of a Bennetts Lane business. The officer approached Ellery's patrol car and found him unresponsive in the driver's seat, the release says.

The responding officer, who also is an EMT, determined that Ellery was experiencing an opiate overdose because he was cyanotic, had no carotid pulse, and was not breathing. The officer removed Ellery from the vehicle and administered two doses of Naloxone to revive him.

After receiving the two doses of Naloxone and before the officer could commence CPR, Ellery regained consciousness. He was then transported to Robert Wood Johnson University Hospital in New Brunswick by EMS personnel, the release says.

Ellery's pleas come just two weeks after John Fodor took over as the officer in charge of the Franklin Township Police Department.

The June 30 appointment of Fodor to supervise the department's day-to-day operations coincided with the June 30 retirement of the Franklin Township Police Department's top two ranking officers, although it was unclear whether Police Chief Richard Grammar and Capt. Gregory Borlan left voluntarily.

In addition to supervising the day to day operations of the department, Fodor is overseeing a top-to-bottom evaluation of the department conducted by the prosecutor staff and to ensure that the policies, procedures, personnel and operations of the department are followed, officials have said.

Follow Suzanne Russell on Twitter @SRussellMyCJ.