GOSHEN - A registered sex offender pleaded guilty on Friday to murdering a worker at the transitional housing program where he lived in the City of Newburgh.

Wilfredo Mercado, 52, pleaded guilty to second-degree murder, admitting that he fatally stabbed Robert Munson at about 11:15 p.m. on May 23, 2017 at 44 Grand St.

In exchange for the guilty plea, Assistant District Attorney Jason Rosenwasser will recommend a sentence of 22 years to life in prison. Judge Craig Brown promised to cap the sentence at 21 to life.

The 44 Grand St. property housed a transitional program for homeless men, including some sex offenders.

Mercado is a level three sex offender based on a 1991 first-degree rape conviction in the Bronx. He was also convicted in 2013 of third-degree burglary in Orange County Court.

Prosecutors have said that Mercado beat, choked and stabbed Munson.

As Brown questioned him, Mercado admitted that he stabbed Munson, and that the stab wounds were the cause of Munson’s death.

Mercado occasionally paused during the questioning to consult with his lawyer, Natasha DuBois, before answering.

Mercado remains in Orange County Jail. He will be sentenced on Jan. 8.