A Panamanian judge acquitted three North Koreans detained last year for trying to transport undeclared Cuban weapons through the Panama Canal and ordered their immediate release.
The North Korean freighter Chong Chon Gang was stopped last July and discovered to be carrying 25 containers of Cuban military hardware, including two Soviet-era MiG-21 aircraft, air defence systems, missiles and command and control vehicles.
The ship's 35-man crew was arrested and the vessel and cargo seized for potential violations of a UN weapons embargo and as a threat to the canal's security.
Panama previously released all crewmembers except three senior officers charged with arms trafficking.
On Friday, Judge Carlos Villarreal finally acquitted and freed the officers. He also acquitted the other 32 crew members.
Villarreal's decision was based on the fact that the incident "was of international character and outside Panamanian jurisdiction".
Panama only had the right to convene the United Nations Security Council to allow the body to issue its own ruling on the weapons cache found, the judge said.
Additionally, the crew members could not be held responsible because "they were executing and obeying direct orders from the state of North Korea," he said.
Villarreal ordered the return of the more than 200,000 sacks of sugar that had been used to conceal the undeclared weapons cargo, but did not release the confiscated arms, saying that the rightful owner had yet to be proven.
The sailors' lawyer, Julio Berrios, said: "The law was applied and this judge will be remembered for being brave and daring to liberate North Koreans despite internal and external pressures against the accused.
"If all goes well, they will be leaving the country at the end of next week via Havana, Moscow and Beijing."
Both Havana and Pyongyang said the weapons were obsolete Cuban arms being shipped to North Korea for refurbishment under a legitimate contract and due to be returned to Cuba.