Another 17 members of the group, broken up in January 2014, were jailed for between three and 10 years in connection with their activities, mostly in the north of the country.
The soldier had served in Melilla, one of two Spanish enclaves on Morocco's Mediterranean coast. Moroccan authorities said that after leaving the army, he joined Al-Qaeda and fought in Afghanistan.
All 18 were charged with forming a criminal group for the purpose of carrying out acts of terrorism, as well as belonging to a banned religious organisation and of holding public meetings without permission.
According to official figures, some 1,500 Moroccans are fighting or have fought in the ranks of jihadist organisations such as the Islamic State group, and Rabat is actively engaged in seeking to dismantle militant cells.
Dozens of people have been jailed in recent months on charges of terrorism.