MADRID, Spain (CNN) -- A Spanish court on Wednesday delivered a mixed verdict in the trial of 28 defendants charged in the 2004 Madrid train bombings, convicting three of mass murder but delivering lesser convictions against the others.
The three-judge panel delivered the verdict as most of the defendants watched from wooden benches in a glass-enclosed area of the courtroom.
Of the 28 men on trial, eight were considered prime defendants for being either the alleged bombers, alleged ideologues, or "necessary cooperators" in the fatal plot. Each of the eight faced 191 charges of mass murder and more than 1,800 charges of attempted murder.
The other men on trial faced charges of membership in or collaboration with a terrorist group, or taking part in an explosives trafficking ring which was part of the plot.
The Associated Press quoted Prime Minister Jose Luis Rodriguez Zapatero, who was elected only days after the bombings, as saying: "Justice was rendered today. The barbarism perpetrated on March 11, 2004, has left a deep imprint of pain on our collective memory, an imprint that stays with us as a homage to the victims."
The coordinated train bombings struck on the morning of March 11, 2004, at Atocha station in central Madrid. They were the most serious terrorist attacks in western Europe since al Qaeda became active. Watch how victims of the bombings are coping
The prime defendants convicted of mass murder were Jamal Zougam and Othman El Gnaoui, both Moroccan, and Jose Emilio Suarez Trashorras, a Spaniard.
They were sentenced to thousands of years in prison but will serve no more than 40, the maximum penalty under Spanish law.
The prime defendants acquitted of mass murder but found guilty of lesser charges included Abdelmajid Bouchar and Youssef Belhadj, both convicted of membership in a terrorist group and sentenced to 12 years in prison.
Hassan el Haski will serve 15 years for leadership in a terrorist group, and Rafa Zouhier will serve 10 years for transporting explosives.
The prime defendant acquitted of all charges was Rabei Osman El Sayed Ahmed, an Egyptian. In all, the judges found 21 of the 28 defendants guilty of at least some of the charges they faced. The five-month trial started in February and heard from hundreds of witnesses and experts.
Italian police provided recorded wiretaps of Ahmed in the months before the bombings in which he allegedly boasted the attacks were his "project." On the stand he condemned the attacks, denied any link and said the voice on the tapes was not his.
Each of the primary defendants found guilty of mass murder faces sentences of nearly 39,000 years -- calculated at 30 years for each of the 191 people killed in the bombings and 18 years, for attempted murder, against each of the wounded.
Various other defendants, including Spaniards accused of providing the explosives, were convicted on less serious charges as well.
All the defendants proclaimed their innocence in the opening days of the trial.
Prosecutors had said that those on trial were Islamic terrorists who were based in Spain but inspired by al Qaeda. Most were Moroccans but nine were Spaniards, accused of providing stolen explosives that were used in the attacks.
The five-month trial started in February with 29 defendants, but prosecutors later dropped all charges against one, Moroccan-born Brahim Moussaten, for lack of evidence. Watch the start of the trial
His brother, Mohamed Moussaten, remained on trial, accused of collaborating with terrorism. The brothers' uncle, Youssef Belhadj, was also on trial, accused of masterminding the bombings.
Also on trial was Hamid Ahmidan, accused of collaborating with a terrorist group and drug trafficking. Ahmidan's cousin Jamal was one of seven prime suspects who blew himself up three weeks after the attacks when police closed in on their suburban Madrid hideout.
Prosecutors said two other Moroccan-born defendants, Rafa Zouhier and Othman El Gnaoui, were "necessary cooperators" in the attacks.
Zouhier was crucial to the plot, prosecutors said, because he was an intermediary between an Islamic terrorist cell in Spain and a group of Spaniards who were trafficking in explosives.
El Gnaoui ensured that explosives were transported to a home near Madrid where the bombs were assembled and knew they would be used in a terrorist attack, prosecutors said.
Another "necessary cooperator" was Suarez Trashorras, who prosecutors said led a group of Spaniards who accepted drugs and cash as payment for stolen explosives, which then ended up in the hands of the bombers.
Witnesses testified seeing another defendant, Jamal Zougam, on one of the trains the morning of the bombings. Prosecutors said the only bomb deactivated by police had clues that led straight to him, though Zougam's defense lawyer denied that. E-mail to a friend
CNN Madrid Bureau Chief Al Goodman contributed to this report