Spain's High Court ruled on Monday that the government should refuse a request from the United States to extradite Venezuela's former military intelligence chief.
Former general Hugo Carvajal was arrested on drug trafficking charges by Spanish police in April at the request of Washington, which says it believes he will share incriminating information about Venezuelan leader Nicolas Maduro.
The court said the ex-spy chief would be freed from jail, where he has been held pending the extradition process, but did not say when he would be released. The Spanish government has the final say on extraditions, but it tends to follow the court's rulings.
Carvajal was an ally of Venezuela's late Socialist leader Hugo Chavez and has turned against Maduro, who succeeded Chavez. He has denied accusations he helped Revolutionary Armed Forces of Colombia (FARC) rebels smuggle cocaine to the United States.
During the extradition hearing last week, he said Washington was fabricating the charges, raising doubts about whether he will cooperate in future with the United States.
The court ruled against the extradition despite the state prosecutor's recommendation that the request be satisfied. It will explain its reasoning on Tuesday.