CHICAGO — Residents of a small city in eastern Nebraska voted Monday to banish illegal immigrants from jobs and rental homes, defying an earlier decision by the city’s leaders and setting off what is all but certain to be a costly and closely watched legal challenge.

In Fremont , a meat-packing town of about 25,000 people, unofficial results from The Associated Press late Monday showed that 57 percent of voters approved a referendum barring landlords from renting to those in the country illegally, requiring renters to provide information to the police and to obtain city occupancy licenses, and obliging city businesses to use a federal database to check for illegal immigrants.

Opponents of the new law, including some business and church leaders, had argued that the City of Fremont simply could not afford the new law, which is all but certain to be challenged in court. In a flurry of television commercials and presentations by opponents in the final days before Monday’s vote, opponents said paying to defend such a local law would require a significant cut in Fremont city services or a stiff tax increase — or some combination of the two.

“There were a lot of tears in this room tonight,” said Kristin Ostrom, an opponent who gathered with others in an old V.F.W. building to await the results. “Unfortunately, people have voted for an ordinance that’s going to cost millions of dollars, and that says to the Hispanic community that the Anglo community is saying they are not welcome here. They thought they were coming to a small-town community with small-town values.”