"Today, the ambassador of North Korea DPRK in Spain has been declared persona non grata," the foreign ministry said on its English twitter account.
The ministry added on its Spanish account that the ambassador has until the end of the month to leave the country.
In late August, Spain had warned that Pyongyang's nuclear and ballistic missile programmes "create a serious threat to peace in the region and to global security," saying they "would have consequences on bilateral relations".
The ambassador was also summoned to Madrid at the time and told to reduce the number of diplomatic staff, which include an ambassador and two diplomats, according to a foreign ministry spokeswoman.
The North Korean embassy opened in 2014.
North Korea -- the Democratic People's Republic of Korea (DPRK) -- has repeatedly conducted missile launches in recent months, despite being barred from doing so under United Nations rules.
It carried out its sixth and most powerful nuclear test earlier this month, and fired a long-range ballistic missile over Japan that landed in the Pacific.
It prompted renewed sanctions from the UN Security Council, which is scheduled to meet on Thursday to discuss the matter during the annual General Assembly gathering of world leaders at the United Nations.
This latest move by Spain followed decisions from both Peru and Mexico to expel the North Korean ambassador on their territory.