"These attacks were being prepared long before the Iraq war. They were not the result of the Iraq war even though many people said so," Aznar said during 11 hours of combative testimony on Monday to a parliamentary commission probing the attacks.
The 11 March bombings aboard four packed commuter trains killed 191 people and wounded 1900 three days before a general election.
And Aznar's mistakenly placing blame on the Basque separatist group Euskadi Ta Askatasuna (Eta) was widely believed to have helped the anti-war Socialist opposition win on polling day.
Had Eta been responsible, it could have helped Aznar in the election by seeming to justify his hard line against the group.
The Madrid bombings suspects - mostly North Africans who investigators say were waging a holy war against the West - made videotapes claiming the attacks in the name of al-Qaida in Europe and said they were seeking revenge for Spain's dispatch of troops to Iraq and Afghanistan.
Aznar, making the first appearance by a former prime minister in a parliamentary inquiry, sought to defend his political legacy and give a boost to the now-opposition party with an appearance marked by political jousting and mutual accusations of lying.
Outside parliament, small groups of pro- and anti-Aznar protesters were kept separated by police.
Demonstrators said Aznar's
hands were covered in blood
"Aznar's hands are covered with blood. He is responsible for provoking this by involving us in the war," said Carmen Aguado, 52, whose son Juan Carlos, 27, was killed in the blasts.
Aznar fiercely fought back against accusations his government was responsible for the attacks because of the Iraq war, saying: "The only ones responsible are the terrorists."
Aznar chose not to seek a third term in the 14 March election and picked his protege, Mariano Rajoy, as the conservative Popular Party's candidate for the presidency.
Socialist Jose Luis Rodriguez Zapatero defeated Rajoy and on taking office immediately made good on his campaign promise to withdraw Spanish troops from Iraq.
"I am absolutely convinced, as I have said before, that the 11 March attacks sought not only a large number of victims. They sought to overturn the electoral situation in Spain," Aznar said.
Zapatero kept his pledge and
withdrew troops from Iraq
He declined to answer which way the election might have been swayed, telling one questioner: "You know."
Zapatero is due to testify on 13 December.
Aznar defended his decision initially to blame the train bombings on Eta, and called for further investigation into possible links between Eta and "Muslim militants" - ties that most experts have discarded.
Eta prime suspect
Aznar testified repeatedly that police commanders all believed Eta was the prime suspect until the election eve.
"My conscience is clear. We told the truth about what we knew," he said.
Eta has killed about 850 people during a 36-year-old campaign for Basque independence.
The parliamentary commission aims to offer a public account of the most devastating attack in modern Spanish history and is separate from the criminal investigation.
Nearly 30 people are in custody or under court supervision for the train bombings.
One minor has been convicted, seven prime suspects are dead, and two or three others remain at large.