A 19-year-old accused of making homemade explosives and plotting to attack a mosque in the Chicago area pleaded guilty Friday to providing material support to terrorists.

Xavier Pelkey appeared in federal court to enter the plea under an agreement in which prosecutors dropped a second charge. He faces up to 15 years in prison when he’s sentenced at a later date.

Pelkey of Waterville was 18 when he was arrested last year by FBI agents who found three homemade explosives in his residence, along with a handwritten document that appeared to be a draft statement about the planned mosque attack. In the statement, Pelkey claimed allegiance to the Islamic State group and an IS flag was painted on his bedroom wall, investigators said.

He had been communicating with two juveniles in Canada and in Illinois about conducting a mass shooting at a Shiite mosque in the Chicago area, law enforcement officials said.

All three believed in a radical form of Sunni Islam that views the Shiite branch of Islam as nonbelievers, officials said. Pelkey planned to contribute firearms, ammunition and explosives to be used in the attack, officials said.