(Reuters) - A Maryland man on Friday pleaded guilty to conspiring to support the Islamist militant group al Shabaab, admitting that he traveled to Somalia to receive military training from the group.

Maalik Alim Jones, 32, entered his plea to three criminal counts before U.S. District Judge Paul Gardephe in Manhattan. Jones admitted that he carried an AK-47 automatic assault rifle for al Shabaab, which is allied with al Qaeda.

“I knew that my actions were a violation of the laws of the United States,” he said.

As part of his plea, Jones agreed to give up the right to appeal any sentence less than 50 years. He faces up to life in prison.

Al Shabaab, which seeks to overthrow Somalia’s Western-backed government and impose a strict version of sharia, or Islamic law, has carried out violent attacks in Kenya and Ethiopia.

Jones was charged in January 2016. Prosecutors said at the time that Jones, who was born and lived in Maryland, traveled in 2011 to Kenya and then to Somalia, where he was brought to an al Shabaab training camp.

Authorities said Jones trained with the group for three months, reading and interpreting the Koran and learning how to handle weapons, including an AK-47 and rocket-propelled grenades.

He then became a member of a specialized fighting force within al Shabaab known as Jaysh Ayman that carried out attacks and raids across the border in Kenya and participated in a battle against Kenyan soldiers in the Somali town of Afmadow, prosecutors said.

Jones was taken into custody by Somali authorities on Dec. 7 while he was attempting to procure a boat to depart for Yemen, according to prosecutors.