A Nigerian terrorist who joined with al-Qaida operatives in Yemen was sentenced to 22 years in prison by a federal judge in Brooklyn Wednesday.

Lawal Olaniyi Babafemi posed for pictures in al-Qaida in the Arabian Peninsula’s (AQAP) "Inspire" magazine and called for lone wolf attacks inside the U.S.

Babafemi, 35, also traveled to Yemen from Nigeria to get terror training. Federal prosecutors said he practiced shooting with AK-47’s and even wrote rap lyrics hoping to recruit Westerners to commit terror bombings.

“Babafemi travelled to Yemen to receive weapons training and to learn how to contribute to AQAP’s English-language media operation,” said Assistant Attorney General John Carlin.

Investigators said Babafemi joined AQAP after the failed underwear bomb plot in which an AQAP operative targeted a Delta flight heading to Detroit. The FBI said Babafemi took $9,000 in cash from cleric Anwar al-Awlaki to try to recruit other Nigerians to carry out attacks. Al-Awlaki was later killed in a U.S. drone strike.

Babafemi was arrested and flown to New York for trial.

He pleaded guilty in April 2014.