An attempt to block undocumented immigrant students from qualifying for in-state tuition at Virginia’s public colleges failed Tuesday in the state Senate on a narrow vote, a symbolic victory for Dream Act advocates.

After a lengthy and testy debate, one Republican joined Democrats to defeat the bill: Sen. John C. Watkins (Powhatan), a moderate Senate veteran retiring this year. Another Republican, Sen. Jill Holtzman Vogel (Fauquier), did not vote.

In a session in which Democrats are trying to force votes on controversial issues that Republicans are largely hoping to avoid, the bill was a rare flash point sparked by conservatives.

The legislation proposed by Sen. Richard H. Black (R-Loudoun) is a response to a decision by state Attorney General Mark R. Herring (D) in April allowing many students brought to the United States illegally as children to benefit from lower tuition rates.

There was a loud burst of applause from the Senate gallery when the bill failed.

“It’s heartening to see a bipartisan group of Senators showed compassion and fairness towards these young people,” Herring said in a statement.

Several undocumented immigrant students came to the Capitol last week to protest the bill.

“It’s going to scare a lot of immigrant students, and we don’t want that fear in the community,” said Rolando Flores Santos, 19, who attends George Mason University.

Black focused his argument on potential legal and financial ramifications of the expanded discount, saying that under a 1996 federal law, it would force the state to grant in-state tuition to any citizen in the country.

Moreover, he said, the legality of President Obama’s immigration initiatives was still in doubt.

“No one at this point can say definitively how the U.S. Supreme Court will eventually rule,” Black said. “I do not believe that this is something we can take a risk on.”

Herring has said that because these students are “lawfully present” in the United States under Obama’s deferred action program, that language does not apply.

Only 81 undocumented students are thus far paying in-state tuition at Virginia public colleges or universities as a result of Herring’s decision. But more than 9,000 Virginia residents have been approved for deferred action.

At least 18 states have laws allowing undocumented immigrants to qualify for in-state college tuition, according to the National Conference of State Legislatures. Lawsuits in California and Kansas brought by out-of-state students on the basis of the 1996 law have failed. However, in 2004, a Virginia federal judge wrote that in his opinion the law did call for in-state tuition to be granted to all citizens in such a case.

Gov. Terry McAuliffe (D) announced last week that he would veto the legislation, calling it, through a spokesman, “counterproductive and mean-spirited.”

An identical House bill put forward by Del. David I. Ramadan (R-Loudoun) has yet to receive a vote.

The legal argument was not the one made by Black and Ramadan in advance of the 2015 General Assembly session, when both focused on what they saw as the fundamental unfairness of allowing illegal immigrants to benefit from tuition breaks when many citizens fail to gain entry at top state schools.

Democrats were vocal and visible in their opposition.

Sen. A. Donald McEachin (D-Henrico), citing Leviticus, said: “The alien living with you do not mistreat him. Treat the resident alien the same way you treat the native born among you.”

Black’s warning of lawsuits is “inaccurate and misleading,” said Sen. Mamie E. Locke (D-Hampton). “These are students from hardworking families who have been paying into the system just like everybody else. . . . They are lawfully present, and they deserve affordable college access.”

Only two of Black’s fellow Republicans spoke in defense of the legislation: Sens. Thomas A. Garrett Jr. (Louisa) and Ralph K. Smith (Roanoke County). Both pointed out that children moved out of Virginia by their parents were also deprived of in-state tuition through no fault of their own.

“This is something that’s created by special carve-out for political reasons,” Smith said.

The political concerns are tricky for Republicans, who by aggressively fighting Herring may hamper their attempts to court an increasingly diverse state population.

Democrats, on the other hand, are using the politics in their favor. U.S. Sen. Mark R. Warner (D-Va.) sent out a fundraising e-mail during the vote, asking supporters “to join us today and tell the Virginia Senate to stop attacking DREAMers.”

Correction: This article originally misattributed a statement made by Sen. Mamie E. Locke (D-Hampton) to Sen. L. Louise Lucas (D-Portsmouth).