A federal judge yesterday cleared Oregon lawyer Brandon Mayfield of any connection to the March terrorist bombings in Madrid, saying the FBI had erroneously matched his fingerprint to a latent print found on a bag of bomb detonators shortly after the attack.

The FBI apologized to Mayfield and his family "for the hardships that this matter has caused." It blamed the error on similarities between the fingerprints and the poor quality of digital fingerprint images provided by Spanish authorities.

According to the U.S. attorney in Portland, Ore., four FBI fingerprint examiners and an independent expert hired by Mayfield's lawyer had agreed that the print belonged to Mayfield, 37. But Spanish officials, who had been doubtful of the fingerprint match, announced last week that the print belongs to an Algerian man, prompting the FBI to review its findings and agree it had erred.

The FBI said it will review its guidelines for handling fingerprint images and will ask an international panel of fingerprint experts to examine its work in the case.

Mayfield, speaking to reporters in Portland, said that what happened to him "shouldn't happen to anybody, at least in the manner it happened to me."

"This has caused a lot of trauma to myself and to my family," he said. "I am two or three days out of the detention center, and I am just now starting to not shake."

Mayfield was arrested on a material witness warrant May 6 and jailed for two weeks. He was released from custody Thursday but remained a material witness until U.S. District Judge Robert Jones yesterday ordered all proceedings dropped. Jones instructed authorities to return Mayfield's seized property and destroy all copies of documents they took from him.

The March 11 train bombings in Madrid killed 191 people and injured 2,000. Spanish investigators have blamed the blasts on Islamic militants tied to al Qaeda.

The print was found on a bag left in a van near a train station where three of the four bombed trains originated. Spanish police sent copies of it to other law enforcement agencies, and the FBI, after making the apparent match, put Mayfield under surveillance. He was rushed into federal custody May 6 when word leaked to the media, prompting the federal court in Portland to issue a gag order on all parties in the case.

U.S. Attorney Karin Immergut said in a motion dropping the case that "facts developed during the preliminary stages of the investigation, when coupled with the fingerprint identification, suggested that Mayfield may have information relevant to the Madrid bombings." But without the fingerprint match, authorities concluded, there is no probable cause to believe Mayfield has any such information.

Mayfield's only known link to Islamic extremists involved his work in a child custody case for a Portland man convicted of attempting to get into Afghanistan to fight U.S. troops. Mayfield is a convert to Islam, but Immergut said at a news conference that his detention "was not based on his religious beliefs."

The FBI statement said two fingerprint examiners were dispatched to Madrid when Spanish authorities alerted the bureau to "additional information that cast doubt on our findings." There they compared the image the FBI had been given to the image Spanish police had.

They determined that the FBI identification was based "on an image of substandard quality," complicated by a "remarkable number of points of similarity" between Mayfield's prints and the latent print obtained by Spanish police.

Minutes of court proceedings unsealed yesterday show that last Wednesday, a fingerprint expert chosen by Mayfield's lawyers confirmed in his testimony the fingerprint match.

The next day, as the Spanish police issued their conclusions, Mayfield was ordered released from jail. The court said then that he remained a material witness; he was placed under court supervision and prevented from leaving the state.

Harden reported from Seattle.