NEW BRUNSWICK, New Jersey — The longtime pastor of a Catholic church who took nearly $517,000 in parish funds has been sentenced to seven years in state prison.

Father Douglas Haefner was sentenced Tuesday and is due to start serving his term Aug. 19. However, he has applied for the state’s Intensive Supervised Parole program, which allows prisoners to serve all or part of their sentences at home

Haefner, 68, was the pastor of St. Matthias Parish in Somerset for 27 years. He pleaded guilty to theft in May, blaming his actions on unspecified “compulsive behavior.”

Authorities said Haefner stole $516,985 over several years. He resigned in November 2018 as church officials were finally conducting an audit that had long been delayed by Haefner, who had repeatedly asked to reschedule due to health problems and the need for more time to prepare.

St. Matthias is part of the Diocese of Metuchen, which covers Hunterdon, Middlesex, Somerset and Warren counties.