The Spanish people elected their Government, to run the country for them and to make decision for them. This includes foreign policy, law and order etc.
The Spanish Government chose to take part in various actions around the world, presumably because they believed it was the right thing to do.
There were terrorists attacks in Spain, these may have been as a result of the actions of the Spanish people, around the world. Once the Government is elected they act on behalf of the people.
The Spanish people decided that they did not wish to re-elect the same Government. Given that so many appear to have disagreed with their Governments decisions, that is hardly surprising. (I have only ever read the figure 80-90 % here, I am not aware of the scope or accuracy of this figure).
Did the bombings have an effect on the election result, almost certainly I would have thought. However to assume that the incumbent Government would have won otherwise is incorrect. Particularly if the vast bulk of the electorate did not agree with various major policy decisions.
As an aside, a lot if not most of the political commentators and terrorism experts I heard at the time in the UK also believed it to be ETA. As such I am not certain that the Spanish authorities tried to mislead their people.