Pierre Robert told the Rabat court that he infiltrated Muslim groups and carried out investigations on behalf of the French intelligence services, the DST.
"I was contacted at the time of the (football) World Cup in 1998 by the DST to conduct inquiries into Algerian Islamist networks in France, and I did that," said Robert, who faces the death penalty if found guilty.
Robert said that after successfully carrying out his first undercover operation for French intelligence, he was asked by his contact at the DST, whom he named only as "Mr Luc", to investigate "Islamist activities in Belgium."
Robert and his 33 co-accused are charged with criminal conspiracy, conspiracy to undermine state security, premeditated murder and possession of arms and explosives in connection with the attacks in Casablanca.
On the evening of 16 May, booby-trapped cars exploded outside an international hotel, a Jewish cultural centre and an Italian restaurant. Suicide bombers also detonated themselves at a Spanish club and a Jewish cemetery, all in downtown Casablanca.
Forty-one people died instantly, including 12 presumed bombers. Four more people died of their injuries in the days and weeks that followed, the latest victim being a 34-year-old Moroccan who died on 16 August.
Born in Saint-Etienne, central France, Robert lives in Tangiers with his Moroccan wife and two children.