An Algerian man believed to be the last domestic detainee still in custody from a national dragnet after Sept. 11 — and who was cleared of links to terrorism in November 2001 — was set free this week, his lawyer said Friday.

Benemar Benatta, 32, went to Ontario, Canada, where he is seeking political asylum, after being released from a Buffalo immigration lockup Thursday, attorney Catherine Amirfar said.

"After five years, he had become all but hopeless," she said. "Now he's cautiously optimistic."

Benatta was among 1,200 mostly Arab and Muslim men detained nationwide as potential suspects or witnesses in the investigation following the terrorist attacks. The government has refused to discuss their fate, but human rights groups have said they believed the former Algerian air force lieutenant was the only one still in custody.

Heather Tasker, a spokeswoman for the U.S. attorney in Manhattan, refused to discuss Benatta's release, which was first reported by The Washington Post.

U.S. officials agreed to release Benatta after the Canadian Consulate General's office in Buffalo granted him temporary residency, according to court papers filed Wednesday in New York.

The last detainee's odyssey began Sept. 5, 2001, when, after overstaying a six-month visa, he crossed the border near Buffalo to seek asylum in Canada. After theSept. 11 attacks, his background as a Muslim man with flight experience prompted Canadian officials to turn him over to U.S. authorities.

He spent the next six months in solitary confinement in a federal jail in Brooklyn. Though the FBI concluded he had no links to terrorism, he was eventually charged with carrying false identification — a case that was dropped after a federal magistrate found his right to due process had been violated.

The magistrate wrote in a 2003 decision that Benatta had been "undeniably deprived of his liberty," and "held in custody under harsh conditions which can be said to be oppressive."

Despite the ruling, immigration officials kept him in custody in Buffalo while he appealed a deportation order and renewed his quest for asylum based on a claim that, as a military deserter, he would tortured or killed if he returned to Algeria.

A United Nations human rights group that studied the case noted that most asylum seekers are released pending the outcome of their cases.

"The imprisonment Mr. Benatta has endured has been a de facto prison sentence," the U.N. group wrote in findings made public in March. "In no way can the simple administrative offense of having stayed in the United States after his visa had expired justify such a disproportionate sentence."