Spain's evacuation effort in Kabul ended on Friday 27 August with dozens of Spaniards, including embassy staff, flown out of the Afghan capital, the government in Madrid said.
The last remaining 81 Spaniards in Afghanistan arrived in Dubai on an Airbus A400M military transport plane.
The passengers included Ambassador Gabriel Ferran, embassy employees and military personnel.
Madrid said that over the course of its mission local Afghan employees of Spain, other EU countries, the United Nations and NATO were taken out of Afghanistan, along with their families.
In Spain's last two flights, four military personnel from Portugal and 85 Afghan personnel who had worked with Spain, Portugal and NATO were evacuated, the government said.
In the flights organized by Spain, a total of 1,900 people seeking refuge from the Taliban were evacuated, according to official data.
The Spanish withdrawal comes just a day after attacks near Kabul airport killed 13 US soldiers and dozens of Afghans.