With anti-illegal-immigrant sentiment rising in the United States, a growing number of states are considering legislation that would forbid public universities from offering in-state tuition breaks to illegal immigrants.

But this week, the Maryland legislature, dominated by Democrats, took a step in the opposite direction, voting to guarantee in-state tuition to illegal immigrants. Gov. Martin O’Malley (D) is expected to sign the bill.

Sponsors overcame years of entrenched opposition with a provision that steers undocumented students to community colleges instead of the increasingly competitive flagship school, the University of Maryland, lessening the risk that they will crowd out others for coveted spots.

Whether illegal immigrants should reap the benefits of residency at public universities is one of the more contentious issues to emerge in the national immigration debate. In this legislative session alone, at least eight states took up bills to extend in-state tuition to illegal immigrants and as many considered bills to deny it, according to the National Conference of State Legislatures. Maryland is the only state this year to pass a bill extending benefits.

Overall, the clear trend is toward ending tuition breaks. At least three states, including Arizona, Colorado and Georgia, have moved to deny in-state tuition to illegal immigrants since 2006. South Carolina barred illegal immigrants from even enrolling in state colleges. Some Virginia lawmakers have tried repeatedly to enact a similar law.

At least 10 states, including California and Texas, have laws that offer in-state tuition to illegal immigrants, but most were passed in the first half of the past decade. Now, several repeal efforts are underway.

“I think it’s bad public policy, and I think it’s a terrible use of tax dollars to subsidize an illegal behavior,” said Carl Wimmer, a Republican state legislator in Utah who has worked to undo a 2002 state law that allows in-state tuition for illegal immigrants in his state.

Supporters of tuition breaks, including most of the higher education community, hope Maryland’s bill will inspire others.

“I think this is a momentum-changer,” said Dan Hurley, director of state relations and policy analysis at the American Association of State Colleges and Universities in Washington.

Tuition discounts would mean the difference between “going to college or not going to college,” said one 18-year-old Silver Spring student who spoke on condition of anonymity because he is here illegally. “That’s what it means to me. Because we’re not eligible for aid or scholarships, there’s no way I’ll be able to come up with $24,000 a year.”

That is what he would pay as a nonresident student at Maryland. He studies now at Montgomery College, which has a long-standing policy of allowing undocumented immigrants to pay lower resident tuition if they graduated from the county’s public schools. Most other public colleges and universities in the Washington region charge out-of-state rates to illegal immigrants.

Maryland state Sen. Victor R. Ramirez, a Democrat from Prince George’s County, has pushed his bill since 2003. (It passed that year but was vetoed by then-Gov. Robert L. Ehrlich Jr.) Even in Maryland, such legislation rouses fears about undocumented students crowding out others at state universities.

The University of Maryland has an admission rate of about 40 percent. The school is allowed to reserve up to 30 percent of freshman slots for nonresidents. Tuition discounts might prompt more undocumented immigrants to apply, potentially putting them in competition with other Marylanders.

The bill countered those concerns by diverting illegal immigrants from the freshman admission cycle. To qualify for discounts, these students would have to spend the first two years at a community college, then transfer to a four-year institution. Community colleges have open enrollment, although their students still face competition to get seats in popular classes.

“I can feel satisfied knowing that nobody’s going to be displaced,” said Ramirez, a Salvadoran immigrant who attended the public Frostburg State University.

Proponents of tuition breaks say such laws are both ethical and practical. Illegal immigrant families pay taxes that fund resident subsidies, they say, and denying them college access arguably hurts the local economy.

“This is for our Maryland residents, because they are,” Ramirez said. “They have been living here for many years, and this is their home.”

Opponents of the measure say Maryland would pay dearly for tuition breaks. An in-state student costs the University of Maryland at least $16,000 in subsidies: That’s the difference between the $8,416 annual tuition and mandatory fees for residents and the $24,831 charged to nonresidents, who effectively pay the full cost of their education.

Even the comparatively low-cost Montgomery College arguably loses $200 for every credit hour taken by an undocumented student with a resident discount.

“You’re talking about $50 million for a thousand kids over four years,” said state Rep. Patrick L. McDonough, a Republican and radio talk-show host from suburban Baltimore. He said he is considering a ballot referendum and a lawsuit to halt the measure.

“I have never seen or witnessed a bill that has generated so much anger and so much fear as this piece of legislation,” he said.