An Oregon lawyer detained two weeks ago after fingerprint evidence appeared to link him to the deadly terrorist train bombings in Madrid was set free yesterday after Spanish police said they determined the fingerprint belonged to an Algerian man.

Brandon Mayfield, 37, a convert to Islam, was released by federal authorities in Portland after being jailed for 14 days under the material witness statute. Authorities have increasingly used the tactic to detain people they think might be associated with terrorists.

Federal authorities in Portland curtailed their surveillance and surreptitious investigation of Mayfield on May 6 and quickly took him into custody when word leaked to reporters of his possible tie to the bombing evidence in Spain.

"I want to thank my family and friends who were supporting me through this -- what I'll call a harrowing ordeal," Mayfield told local television reporters as he was hugged by his wife and three children upon his release. "I want to thank the Multnomah County Detention Center for this lovely holy Koran and this prayer rug, and upon the protective order being lifted at some point, I can talk further about this ordeal."

A gag order, imposed by a federal judge when Mayfield was arrested, was still in effect last night and extends to Mayfield.

Mayfield's attorney, Steven Wax, told reporters outside the Multnomah County courthouse: "The last few weeks of his incarceration have been a terrible ordeal for this man who is himself a lawyer and an honorably discharged officer from the United States Army. He has maintained at the outset that he has had no involvement in the horrible bombing that occurred in Spain in March and he has maintained from the outset that he has no knowledge about that.

"After a tense negotiation, investigation and communication with the government, we are pleased that he is here and that he is released."

Wax said grand jury secrecy rules prevent communication about the case. "That is the reality of our system. It is also part of the reality of this case that some breaks in that secrecy, some leaks that occurred early on, have been quite harmful to Mr. Mayfield," he said.

The fingerprint that set events in motion was lifted from a bag of detonators discovered in a stolen van parked at a station from which three of the bombed Madrid trains departed. The bag contained detonators similar to those used in the attack that killed 191 and injured more than 2,000. Spanish police were unable to identify one of the fingerprints on the bag and circulated it to other countries. The FBI linked it to Mayfield, who previously served in the military.

In Madrid late yesterday, authorities said the fingerprints found on the plastic bag belonged to an Algerian, Ouhnane Daoud, the Associated Press reported.

Although some at the FBI were confident in the match, the Spanish police were doubtful all along.

"No one has ever come out officially and said anything about fingerprints," an FBI official who declined to be named because of the gag order said last night . "The fact that his name is even out there to begin with is rather unfortunate."

The investigation's status, and whether it has been ended, was not clear last night.

Mayfield's friends and family insisted on his innocence, noting he had not left the country in a decade.

Apart from the fingerprint, Mayfield's only publicly known link to Islamic extremists was his legal work on a custody issue for Jeffrey Leon Battle, a Portland man who was sentenced to 18 years in prison for conspiring to fight against U.S. troops in Afghanistan.

Word that an American was under investigation in the Madrid bombings circulated when Newsweek called Portland authorities for comment -- then on May 6 posted a report on the Internet. Portland FBI agents, who had been quietly investigating Mayfield for weeks and were not prepared to charge him with a crime, feared he would flee or destroy potential evidence. They quickly placed him under arrest and conducted a search of his home and office.

Mayfield's brother, Kent, who accompanied Mayfield last night, told reporters: "I think there is going to be a major review about why they detained him. . . . This obviously proves that this was a complete witch hunt."

AveNell Mayfield, who traveled from Hutchinson, Kan., to Portland to be with her son's Egyptian-born wife, Mona, and his children after the detention, said in a telephone interview that he "is really a mellow person, he has a lot of mental discipline. He said his training as an Army officer and his faith have kept him positive, and he urged us to do the same."

Her son's name, she complained, has been "smeared internationally."

Harden reported from Seattle.