(CN) - A federal judge in Washington, D.C., ordered the release of a Yemeni detainee, saying the government's case to keep him at Guantanamo relies too heavily on confessions tainted by torture.

U.S. District Judge Ricardo Urbina ruled that Saeed Mohammed Saleh Hatim's confession that he was part of al-Qaida in Afghanistan was unreliable, because it was allegedly obtained under torture in Afghanistan.

Hatim was captured in Pakistan in November 2001 and was held for six months in Kandahar, Afghanistan, where he was allegedly beaten and threatened with rape.

"The government's allegations rest almost entirely upon admissions made by the petitioner himself - admissions that the petitioner contends he made only because he had previously been tortured while in U.S. custody," Urbina wrote.

The government claimed that Hatim trained at the al-Farouq terrorist camp, stayed at al-Qaida safehouses, and fought against U.S. and coalition forces at the Battle of Tora Bora in Afghanistan in December 2001.

"[T]he government faces a steep uphill climb in attempting to persuade the court that the petitioner's detention is justified based on the allegation that he trained at al-Farouq, given that the sole evidence offered in support of that allegation is tainted by torture."

Hatim never admitted to fighting against the U.S. and allied forces, and there is no evidence that he was part of al-Qaida when he stayed at the guesthouses, the judge found.

American counter-terrorism specialists and Saddam Hussein's former intelligence officers have forged an unlikely alliance in Yemen to tackle al-Qaeda.

By Adrian Blomfield in Sana'a

Published: 7:00PM GMT 06 Jan 2010

Baathist officers who fled Iraq in the wake of the fall of Saddam are working with US intelligence Photo: REUTERS

The two sides were enemies on the battlefield just seven years ago but have been brought together by the failings of Yemen's security and intelligence apparatus, according to diplomatic and military sources in the country.

Although mutual suspicions linger, the collaboration is said to have achieved some intelligence breakthroughs and helped instil greater efficiency and professionalism within the most elite Yemeni counterterrorism outfit.

Co-operation with the former Baathist officers, who fled Iraq in the wake of the US-led invasion and the fall of Saddam, is expected to grow further in the wake of the failed terror attack in the skies above Detroit.

Both Britain and the United States have pledged to bolster Yemeni efforts to take on al-Qaeda's local affiliate, al-Qaeda in the ArabPeninsula (AQAP), since it claimed responsibility for a thwarted attempt to bring down an American airliner on Christmas Day.

The US-Iraqi alliance was born out of frustration over the incompetence and suspected al-Qaeda sympathies of many within Yemen's domestic intelligence body, the Political Security Organisation, or PSO.

"We do not know where the allegiance of many in the intelligence apparatus lies," said a western diplomat.

According to many Yemen observers, the PSO was instrumental in the resurrection of al-Qaeda's fortunes after it was accused of complicity in the escape of 23 terror suspects from one of its prisons in 2006.

Nasir al-Wahayshi, AQAP's highly effective leader, and several suspects linked to the bombing of the US warship USS Cole of Aden in 2000 were among those who won their freedom.

Under pressure from the United States in the aftermath of the September 11, 2001 attacks, Ali Abdullah Saleh, Yemen's president, created the rival National Security Agency (NSA).

It has taken credit for providing intelligence that led to air strikes last month which, Yemen claims, killed dozens of AQAP operatives

A number of former Iraqi officers, some of them members of Saddam's feared intelligence service, the Mukhabarat, were recruited to the service.

"They are involved in training and also intelligence gathering," said a former Yemeni security officer.

At the outset of its intervention in Iraq in 2003, the United States embarked on a rigorous policy of "de-Baathification" and disbanded the Iraqi army.

Many fled to Syria before receiving an invitation to come to Yemen from President Saleh, according to former Yemeni military officers and analysts.

"After the collapse of the Baathists in Iraq, many came to Yemen," said Fares al-Saqqaf, a prominent analyst. "Many saw it as a transit point, but others stayed here and became government experts."

The Yemeni president was a strong ally of Saddam, and is said to have regarded him as his mentor. He even earned the sobriquet "Little Saddam" for the way he aped the Iraqi leader by wearing a revolver holstered at the seat of his trousers.

Mr Saleh also gave refuge to the relatives of Saddam's top henchman, including the families of Tariq Aziz, the former deputy prime minister, and Izzat al-Douri, one of the Iraqi dictator's closest military allies.

But Mr Saleh's allies also include a number of Salafists, whose puritanical interpretation of Islam is shared by many in al-Qaeda. Many fought against the Soviets in Afghanistan in the 1980s, an experience that brought some into contact with Osama bin Laden.

Although a majority eschew bin Laden's doctrine of violence, the presence of so many Salafists in the government could explain why the CIA did not tell Yemen it had received intelligence of an AQAP plot to set in motion "a Nigerian bomber."

While acknowledging that the Americans and Iraqis do work together, a Western diplomat said the relationship remained ambiguous.

"It shouldn't be overstated but, yes, it looks like there is some crossover," he said.

"The master class has always declared the wars; the subject class has always fought the battles. The master class has had all to gain and nothing to lose, while the subject class has had nothing to gain and everything to lose--especially their lives." Eugene Victor Debs