Top Venezuelan official Gen Hugo Carvajal has been released by the Dutch Caribbean island of Aruba, after being detained over US accusations of drug-trafficking activities.
The US Treasury said he had been protecting drug shipments by Colombian Farc rebels.
But a judge on the island said Gen Carvajal had a diplomatic passport and that his arrest was illegal.
He had been appointed by Venezuela as its consul in Aruba.
Aruba, which is part of the Kingdom of the Netherlands, is located 27km (17 miles) north of Venezuela.
In a statement, Venezuelan Foreign Minister Elias Jaua said Gen Carvajal would be brought home.
"A plane is taking off at this moment ... to go and pick up our comrade Hugo Carvajal," he said.
Gen Carvajal was head of Venezuela's military intelligence between 2004 and 2009.
He was a close ally of the late president, Hugo Chavez, who died of cancer last year.
In 2008, the US Treasury accused him and another senior Venezuelan official of "materially assisting the narcotics trafficking activities of the Revolutionary Armed Forces of Colombia (Farc)".
Mr Chavez rejected the allegations at the time.
The US Treasury announcement came a day after Venezuela expelled the American ambassador to Caracas for allegedly backing an aborted right-wing plot against Mr Chavez.