In a rare public apology, the FBI (search) admitted imprisoning an American lawyer for two weeks after mistakenly linking his fingerprint to one found near the scene of a terrorist bombing in Spain (search).

The apology Monday came hours after a judge dismissed the case against Brandon Mayfield (search), who had been held as a material witness in the Madrid (search) bombings case, which killed 191 people and injured about 2,000 others.

Mayfield, a 37-year-old convert to Islam, sharply criticized the government, calling his time behind bars "humiliating" and "embarrassing" and saying he was targeted because of his faith.

"This whole process has been a harrowing ordeal. It shouldn't happen to anybody," said Mayfield. "I believe I was singled out and discriminated against, I feel, as a Muslim."

Karin J. Immergut, the U.S. attorney in Oregon, denied Mayfield had been a target because of his religion and maintained that the FBI had followed all laws in the case.

Court documents released Monday suggested that the mistaken arrest first sprang from an error by the FBI's supercomputer for matching fingerprints and then was compounded by the FBI's own analysts.

"The FBI apologizes to Mr. Mayfield and his family for the hardships that this matter has caused," the bureau said in a statement. The agency also said it would review its practices on fingerprint analyses.

"We need to know more about how this happened. All of us in this country need to know more about how this type of mistake can be made," said U.S. Public Defender Steve Wax, Mayfield's attorney.

Mayfield, a former Army lieutenant, was released last week. But he was not altogether cleared of suspicion; the government said he remained a material witness and put restrictions on his movements.

Those restrictions were lifted Monday.

U.S. District Judge Robert Jones said all property that had been seized from the Mayfield residence should be returned, and all copies of Mayfield's personal documents held by the federal government were to be destroyed.

The case began when FBI fingerprint examiners in Quantico, Va., searched for possible matches to a digital image of a fingerprint found on a bag of detonators the day of the Spanish bombings on March 11.

The system returned 15 possible matches, including prints belonging to Mayfield, on file from a 1984 burglary arrest in Wichita, Kan., when Mayfield was a teenager.

Three separate FBI examiners narrowed the identification to Mayfield, according to Robert Jordan, the FBI agent in charge of Oregon. A court-appointed fingerprint expert agreed.

The FBI maintained their certainty even as Spanish authorities said by mid-April that the original image of the fingerprint taken directly from the bag did not match Mayfield's, Wax said.

Last week, Spanish authorities said the fingerprints of an Algerian man were on the bag. Jordan said FBI examiners flew to Spain, viewed the original print pattern of the fingerprint on paper, and agreed that it was not Mayfield's.

As additional evidence in support of Mayfield's arrest, the FBI pointed to Mayfield's attendance at a local mosque, his advertising legal services in a publication owned by a man suspected to have links to terrorism, and a telephone call his wife placed to a branch of an Islamic charity with suspected terrorist ties.

They also noted that Mayfield represented a man in a child custody case who later pleaded guilty to conspiring to help Al Qaeda and the Taliban fight U.S. forces in Afghanistan.

According to court documents, FBI agents began their surveillance of Mayfield two weeks after the attacks in the Spanish capital. Under a provision of the U.S. Patriot Act, they entered his home without his knowledge — but aroused the family's suspicion by bolting the wrong lock on their way out and leaving a footprint on the rug that didn't match any family members.

During a later raid, FBI agents took Mayfield's computers, modem, safe deposit key, assorted papers, as well as copies of the Quran and what they classified as "Spanish documents" — apparently Spanish homework by one of Mayfield's sons.

Mayfield, who runs a small Portland law office, was never facing any formal charges. He was arrested as a material witness, and held in the Multnomah County Detention Center on the chance that he might have information about the Spain bombings.

At a press conference, Mayfield talked about his time behind bars, initially in solitary confinement and then in the jail's mental ward. Mayfield feared for his safety when inmates began to recognize him on the nightly news.

"The climate of fear of terror makes this a cautionary tale about the way in which that fear can ensnare an innocent person in the type of abuse to which Mr. Mayfield was subjected," Wax said.