The NATO mission in Afghanistan remains risky even as international forces begin to shift responsibility to Afghan personnel, Spain's defense minister said here Monday, one day after a Spanish soldier was killed by insurgents in the northwestern province of Badghis.

There is "less mission in Afghanistan, but no less danger," Carme Chacon told troops at the Spanish base in the western city of Herat.

The minister traveled to Afghanistan to be briefed on the attack that resulted in the death of Sgt. Joaquin Moya Espejo, who was part of a team training Afghan soldiers deployed in Badghis.

The assault occurred northwest of Ludina, where Afghan troops, Spanish military advisers and a sniper team had taken up position on a hill to protect troops moving through a valley. The soldiers came under small arms fire from a distant position and Moya Espejo, who was wearing a bullet-proof vest, was hit in the chest.

The sergeant was airlifted by a U.S. helicopter to the Role 2 hospital in the village of Bala Morghab, but was pronounced dead on arrival.

Addressing the troops in Herat, Chacon announced that Spanish forces would hand over responsibility for security in two districts of Badghis to Afghan authorities at year's end.

She praised the troops' "excellent work" and told them that King Juan Carlos asked her to convey to them his "support, admiration and gratitude" for their efforts.

A 35-year-old father of one, Moya Espejo was assigned to an infantry regiment in the northern Spanish city of Vitoria.

He was the first Spanish soldier killed by gunfire in an attack since Spain's armed forces began serving with the NATO-led International Security Assistance Force, or ISAF, in Afghanistan in January 2002.

A total of 98 Spanish military personnel have now been killed since the mission in Afghanistan started, with 14 troops dying in insurgent attacks and 79 in air accidents.

All of the roughly 1,500 Spanish soldiers and police serving with ISAF will be withdrawn by the end of 2014, Prime Minister Jose Luis Rodriguez Zapatero said in June.

The 2014 target for an end to ISAF operations was set by NATO members at a summit last October in Lisbon.