85% to 90% of Spaniards were against involvement the Iraq war, and Zapatero had promised to bring back the troops if he was elected.
He was elected and he brought back the troops, just as he had promised. He subsequently increased the number deployed to Afghanistan, which was approved by all political parties and it's generally supported by everyone.
Of course, if the attacks had not happened, probably Zapatero would not have been elected, but the Popular Party ridiculous lies and deceptions regarding the attacks were their own doing. To this day they keep pushing conspiracy theories about the attacks being a conspiracy between elements of the police, the socialist party, spanish, french and moroccan secret services and ETA all disguised as Al-Q just to make them look bad. But they will also say that Al-Q made us leave Iraq... they are not that big on consistence.