In June, a federal judge issued a preliminary injunction against a housing ordinance in Farmers Branch, Tex., that would have imposed fines against landlords who rented to illegal immigrants. In July, the city of Valley Park, Mo., repealed a similar ordinance, after an earlier version was struck down by a state judge and a revision brought new challenges. A week later, a federal judge struck down ordinances in Hazleton, Pa., the first town to enact laws barring illegal immigrants from working or renting homes there.

Image Angelina Guedes has owned a hair and nail salon in Riverside, N.J., for two years. It was nearly empty on a recent afternoon. Credit... Jessica Kourkounis for The New York Times

Muzaffar A. Chishti, director of the New York office of the Migration Policy Institute, a nonprofit group, said Riverside’s decision to repeal its law — which was never enforced — was clearly influenced by the Hazleton ruling, and he predicted that other towns would follow suit.

“People in many towns are now weighing the social, economic and legal costs of pursuing these ordinances,” he said.

Indeed, Riverside, a town of 8,000 nestled across the Delaware River from Philadelphia, has already spent $82,000 defending its ordinance, and it risked having to pay the plaintiffs’ legal fees if it lost in court. The legal battle forced the town to delay road paving projects, the purchase of a dump truck and repairs to town hall, officials said. But while Riverside’s about-face may repair its budget, it may take years to mend the emotional scars that formed when the ordinance “put us on the national map in a bad way,” Mr. Conard said.

Rival advocacy groups in the immigration debate turned this otherwise sleepy town into a litmus test for their causes. As the television cameras rolled, Riverside was branded, in turns, a racist enclave and a town fighting for American values.

Some residents who backed the ban last year were reluctant to discuss their stance now, though they uniformly blamed outsiders for misrepresenting their motives. By and large, they said the ordinance was a success because it drove out illegal immigrants, even if it hurt the town’s economy.

“It changed the face of Riverside a little bit,” said Charles Hilton, the former mayor who pushed for the ordinance. (He was voted out of office last fall but said it was not because he had supported the law.)