A northwest suburban man who twice sold heroin to an undercover police officer was sentenced Friday to 12 years in prison.

Kentrell M. Montgomery, 36, pleaded guilty July 17 to unlawful delivery of a controlled substance within 1,000 feet of a church, according to the Kane County state’s attorney’s office.

Montgomery sold a total of just under three grams of heroin to an undercover officer near two churches in Elgin on Sept. 11, 2015, and again on Sept. 17, 2015, prosecutors said.

The Elgin resident has four previous convictions for drug delivery in Kane and McHenry counties, and has served two prior prison terms, prosecutors said.

Judge John Barsanti sentenced Montgomery to 12 years in prison on Friday.