There were conflicting reports about what caused the crash, the biggest loss of life for NATO forces in Afghanistan. A spokesman for NATO's International Security Assistance Force said the crash and emergency landing in Herat province were believed to be accidents, but Spain's defense minister said he did not rule out hostile fire.
"It could have been an accident or it could have been an attack from the exterior," Jose Bono said in Madrid. Afghan President Hamid Karzai said the crash was caused by a sandstorm.
However, Afghan army commander Abdul Wahab Walizada, whose troops provided security at the crash site, said the weather was fine. He said the helicopters were flying too close together, and the rotor blades of one clipped the other.
One helicopter burned while the other was damaged severely, he said.
The 17 dead -- 12 soldiers and five crew -- were on the chopper that crashed, ISAF spokesman Maj. Andrew Elmes said. The five injured were on the second, which made a "hard landing," he said. They were in stable condition at an ISAF hospital in Herat.
Twelve other troops on the second chopper were not injured.
In Washington, Pentagon spokesman Bryan Whitman said preliminary information showed no indication the aircraft was shot down or collided with another craft.
Bono said two Spanish Cougar AS532 helicopters were flying together at the time. One pilot reported seeing a column of black smoke in a nearby valley, flew closer to the spot, concluded it might signal an attack from the ground and decided to make an emergency landing.
The other helicopter crashed, the defense minister said. Bono said Spanish officials initially believed the crash was likely an accident, but they later saw a photo showing that the area where the helicopter crashed was level, making it conducive to an emergency landing.
That "leads the military high command not to rule out the hypothesis that it could be an attack rather than an accident," he said.
Spanish Prime Minister Jose Luis Rodriguez Zapatero, who broke off his vacation in the Canary Islands to return to Madrid, praised the 17
"They honored a pledge to defend freedom and peace supreme values that Spaniards are very committed to," he said.
Secretary of State Condoleezza Rice called Spain's foreign minister, Miguel Angel Moratinos, to express her condolences, State Department spokesman Sean McCormack said in Washington.
The victims were the first Spanish troops killed in Afghanistan, officials said. Spain has about 800 troops in Afghanistan assisting the NATO-led force.
That 10,000-strong force is in the country ahead of September 18 elections. Elmes said both choppers were on a training mission to support the vote -- the next key step in the country's path to democracy after two decades of war.
Taliban-led rebels have stepped up attacks in the past six months and vowed to sabotage the polls. But they focus their activities in the east and south, rarely striking in Herat and other western areas, where the incidents occurred. NATO plans to take over from the 17,000-strong US-led coalition hunting Taliban and al-Qaeda rebels in the violence-wracked south early next year before moving into the east.
About 1,000 people have died nationwide in violence since March. In the latest fighting, US forces killed six suspected Taliban rebels after they attacked an American base in the southern province of Uruzgan on Sunday, a US military statement said.
The crash was the second major deadly incident involving Spanish troops deployed in Afghanistan. In May 2003, 62 Spanish peacekeepers returning home from Afghanistan died when their Russian-built YAK-42 plane crashed near Trabzon in northwest Turkey. Thirteen Ukrainian and Belarusian crew members of the aircraft also died.
In late June, suspected insurgents shot down a US military Chinook helicopter in volatile eastern Kunar province near the border with Pakistan. All 16 US forces on board were killed.
In April, 15 US service members and three American civilians were killed when their Chinook went down in a sandstorm while returning to the main US base at Bagram.