"The two leaders said they both looked forward to working together, particularly on our shared commitment to fighting terrorism," the White House spokesman, Scott McClellan, said.

But there was no attempt to put a positive spin on the loss of a diplomatic ally and the prospect of losing 1,300 Spanish soldiers in Iraq, with the handover to an interim government only months away.

Washington's hope was that the sharp turnaround in the electoral fortunes of José María Aznar's party signified a specific response to both the bombing and the dispute as to who was responsible, rather than a general reaction among voters against those leaders who had allied themselves with the US in the war against Iraq.

"We don't know how big a factor the Madrid bombing was in the outcome," a senior American official told the New York Times.

"But I wouldn't be telling the truth if I said this is the kind of outcome we might have wished for."

The White House made little effort to disguise who it wanted to win. "I believe that the Spanish people understand that they've had strong and good leadership in José María Aznar and that fighting terrorism cannot allow one to be intimidated," President Bush's national security adviser, Condoleezza Rice, said on Sunday.

The US administration knew the bombings would have an effect at the polls but assumed that they would bolster support for Mr Aznar's party. "I hope this will cause Europeans to rededicate themselves to going after terrorist organisations," said the US secretary of state, Colin Powell.

The fear in the White House is that countries like Italy, Japan and Britain, which have contributed troops to Iraq in the face of mass opposition, may reconsider for fear of a domestic backlash.

Both abroad and at home the concern is more about the diplomatic consequences than the military ones. Spain contributed fewer than 1% of the forces on the ground in Iraq.

One of the battle lines over the war in the run-up to November's election will be Mr Bush's record of alienating potential allies.

"We can only fight terror with the help of our allies," the presumptive Democratic nominee, John Kerry, said recently.