A Long Island man on trial for murder walked away with a sweetheart deal this week after his defense attorney learned a prosecutor had failed to turn over reams of case notes — including evidence others had confessed to the very same murder, according to a report.

Messiah Booker, who had been mid-trial for the 2013 slaying of 21-year-old Demitri Hampton, promptly pleaded guilty to second-degree burglary in exchange for five years behind bars, court records show.

Booker, 32, had previously faced life behind bars if convicted.

Suffolk County DA Thomas Spota immediately asked for prosecutor Glenn Kurtzrock’s resignation, reported the Riverhead News-Review. Kurtzrock complied.

The discovery was made last week when defense attorney Brendan Ahern realized there was a nearly two-year gap in his case notes, according to the report.

A judge then commanded Kurtzrock turn over the records, and Ahern was confronted with 125 pages of new evidence. Ahern later told the court it appeared the newly-discovered paperwork had been “surgically removed” from the documentation he had received.

Hampton was shot in the chest in his Flanders home as he attempted to stop a robbery.

Booker is slotted for sentencing June 9.