UPDATE 1/9/17: Khalil Abu-Rayyan will be sentenced March 13, 2017 in Miami. 

DETROIT (WWJ/AP) – A Dearborn Heights man accused of making threats against a church has pleaded guilty to gun charges.

READ MORE: The Detroit Zoo To Host Its Final Weekend Of Family-Friendly Halloween Event 'Zoo Boo' Oct. 22-24

Khalil Abu-Rayyan was not charged with terrorism-related crimes, but investigators say he’s made threats against a church, police and others in support of Islamic State.

His lawyer says the 22-year-old Abu-Rayyan was simply trying to impress an undercover agent.

Abu-Rayyan pleaded guilty Tuesday to making a false statement to get a firearm and illegally possessing a firearm. The plea wasn’t part of any deal with prosecutors. He’s been in custody without bond since February.

An expert found Abu-Rayyan was competent to face charges. He’ll get his sentence on Jan. 9. The maximum sentence is 10 years in prison on each charge.

According to the documents, Abu-Rayyan was under federal surveillance starting in May 2015. It was found that Abu-Rayyan was posting and retweeting ISIS-supporting posts on Twitter, along with photos of him firing an AK-47 and an AR-25 at a gun range.

Abu-Rayyan allegedly told an undercover agent through social media about his plans for an attack.

READ MORE: Tillson Street's Halloween Displays Draws Thousands

Click here to read the complaint (.pdf format)

“I tried to shoot up a church one day,” Abu-Rayyan posted, according to the complaint. “It’s one of the biggest ones in Detroit. I had it planned out. I bought a bunch of bullets. I practiced reloading and unloading. But my dad searched my car one day and he found everything. He found the gun and the bullets and a mask I was going to wear.”

The church in question went unnamed in the documents, but was said to have 6,000 members. Abu-Rayyan allegedly went on to explain why he picked the church as a target.

“It’s easy, and a lot of people go there,” the post read. “Plus people are not allowed to carry guns in church. Plus it would make the news. Everybody would’ve heard. Honestly I regret not doing it. (If I) can’t go do jihad at the Middle East, I would do my jihad over here.”

Abu-Rayyan was pulled over for speeding on Oct. 7 when officers found an unlicensed pistol inside his car and noticed a strong smell of marijuana. He told police during questioning that he was trying to hide the gun from the officer. He pleaded guilty to possession of marijuana and trial was set for the gun charges.

Just days after pleading guilty to marijuana charges, according to court documents, Abu-Rayyan took to social media again and told the undercover agent that he wanted to kill his arresting officer — who was in the hospital following a heart attack — and that he carries a “large knife or sword” in his car in case he gets into a fight.

“I would gladly behead people if I needed to,” he allegedly told the agent. “It is my dream to behead someone.”

MORE NEWS: Kalamazoo Tests For Lead Exposure Following High-Lead Level Reports In Other Michigan Cities

TM and © Copyright 2016 CBS Radio Inc. and its relevant subsidiaries. CBS RADIO and EYE Logo TM and Copyright 2016 CBS Broadcasting Inc. Used under license. All Rights Reserved. This material may not be published, broadcast, rewritten, or redistributed. The Associated Press contributed to this report.