A Pakistani immigrant detained almost three years ago after taking autumn photographs near an Upstate New York reservoir lost a final appeal on Tuesday and faces deportation.

In the end, dozens of members of Congress, an international circle of supporters and a flurry of petitions could not stop the Bureau of Immigration and Customs Enforcement from issuing a deportation order for Ansar Mahmood, 27. A pizza deliveryman, Mahmood is one of the longest-held detainees from a roundup of Arab and Muslim men in the days after the Sept. 11, 2001, attacks.

Federal officials took Mahmood into custody in October 2001, not long after he asked a stranger to shoot his photo as the sun dipped behind the Catskills Mountains. Federal officials feared that he might be a terrorist scouting the reservoir, which was in the background of the photo, for a possible attack. They later cleared Mahmood of any such suspicions.

But when federal agents searched Mahmood's house, they found evidence that he had co-signed for an apartment and registered a car as a favor to two illegal immigrants. That was a deportable crime, federal immigration officials said.

William Cleary, an immigration field director in Buffalo, wrote to Mahmood: "You received extraordinary benefit under this country's generous immigration system and immediately set out to violate and undermine that very system."

Mahmood's lawyer said the government is being vindictive. This ruling "just shows a lack of compassion by the current administration," Rolando Velasquez said. "Ansar's case highlights just how draconian those [immigration law] changes really are."

Advocates have rallied around the soft-spoken Pakistani, believing that he had become a victim of a roundup that targeted Arab and Muslim immigrants, and was charged with a crime that before the terrorist attacks would have gone unnoticed. Susan Davies, a Chatham, N.Y., resident who helped lead the movement to free Mahmood, said: "His case was so clearly a case of racial profiling, it seemed only right that they shouldn't deport him."

Mahmood, a legal permanent resident, entered the United States in 2000 after winning an immigration lottery. He sent money to Pakistan to support his family there, and his supporters called him a model of what the United States hopes for from its immigrants.

An immigration judge first ordered his deportation in July 2002, a decision upheld this week. Immigration officials said Tuesday that racial profiling was not a factor.

"It has no bearing on the case," said Michael Gilhooly, spokesman for the Bureau of Immigration and Customs Enforcement. "The facts of the case cannot be disputed."

Supporters have vowed to push for a last-minute reprieve. But nothing short of a congressionally approved bill can stop his deportation.

Mary Lavelle, a secretary in Velasquez's office, said she has heard her share of creative client stories, but still took the uncharacteristic move of joining the movement to free Mahmood. Lavelle said she was "brokenhearted" by the ruling.

"If America had Ansars for citizens, this would be such a wonderful place to live," she said. "He is everything we should want for a citizen."

Mahmood called his lawyer's office, Lavelle said, to ask how his supporters had taken the news and then added: " 'Don't worry about me. I'm strong.' "

A legal permanent resident, Ansar Mahmood was detained in October 2001 after taking photographs at a reservoir.