Panama is to free 32 North Korean crew members detained more than four months ago for smuggling Cuban weapons aboard a ship.

Tomas Cabal, head of the anti-terrorism section of Panama's Foreign Ministry, said 32 of the 35 strong crew of the Chong Chon Gang would be freed and should leave the country by Thursday.

The three most senior crew members, including the captain, still face charges of threatening Panama's security by seeking to move undeclared weapons through the Panama Canal.

The crew's return would end part of a bizarre case involving the three countries that provoked international controversy after the ship was seized in July for smuggling Soviet-era arms, including two MiG-21 aircraft, under 10,000 tons of sugar.

Mr Cabal said that "the crew members have effectively been freed. They are drawing up the release order and will go to Havana. I understand they must leave by tomorrow."

Panamanian officials have said the 32 appeared to be ignorant of what was being transported on board the vessel.

It is still unclear what would happen to the ship, because a fine the Panama Canal Authority imposed on the vessel is yet to be paid.

The UN Security Council has yet to decide on penalties to impose on Cuba for breaching a 7-year-old ban against arms transfers to North Korea due to the country's nuclear weapons program.

The arms at the centre of the controversy will most likely be sold or given away, Panama's Foreign Minister Fernando Nunez Fabrega has said.

In July, the North Korean crew sabotaged its electrical system and bilge pumps after Panamanian investigators stopped the ship near the Atlantic entrance to the Panama Canal on suspicion it was carrying drugs.