Virginia Gov. Terry McAuliffe (D) speaks after attending a Muslim community leader roundtable and prayer service at the All Dulles Area Muslim Society Mosque on Feb. 3 in Sterling, Va. (Ricky Carioti/The Washington Post)

Virginia’s Democratic leaders are taking a stand against President Trump over immigration enforcement, with Gov. Terry McAuliffe promising to veto three bills passed by the Republican-controlled legislature designed to help the federal government roust undocumented residents.

The issue is also playing out in state legislatures across the country, where at least 29 states and the District of Columbia are considering legislation in 2017 regarding illegal immigrants.

In Virginia, a bill that would prohibit localities from declaring themselves “sanctuary cities” for undocumented immigrants passed the state Senate on Wednesday, where Republicans hold a slim majority. On the same day, McAuliffe said he would veto it, along with two other measures that would toughen the state’s stand on immigration.

State Attorney General Mark Herring (D) has already challenged Trump’s entry ban in federal court, and the governor’s stand positions the state as one of the more aggressive centers of resistance to the new GOP administration.

The state’s role in federal immigration policy is also becoming a focus of Virginia’s closely watched governor’s race, as Democratic hopefuls Tom Perriello, a former congressman, and Lt. Gov. Ralph Northam have condemned Trump’s actions while their Republican counterparts have supported them. The issue plays one way in vote-rich Northern Virginia, with its high concentration of immigrants, and differently in rural and down-state suburbs.

Virginia is one of 25 states considering legislation this year that would ban the practice of designating sanctuary cities, or places where undocumented people are protected from federal immigration enforcement. Eight other states, plus the District, are considering measures to support sanctuary cities, according to the National Conference of State Legislatures.

All told, more than 60 bills are pending nationwide on issues related to sanctuary cities or immigrant detention, according to NCSL data.

On Wednesday, the Virginia American Civil Liberties Union and several groups that serve the immigrant community — including a number of churches — called on McAuliffe to veto the three bills that are now before him.

His spokesman said that he would.

“He doesn’t agree with efforts to turn state or local law enforcement officials into ICE agents,” spokesman Brian Coy said, referring to the Immigration and Customs Enforcement agency. “Our police and sheriff’s departments already have critical jobs to do without being forced to enforce federal immigration law.”

McAuliffe has written to the Trump administration about the issue and made a point of touting the state’s diversity as an economic asset. On Wednesday, he toured the Fair Price International Supermarket in the Alexandria area of Fairfax County and praised the initiative shown by immigrants.

Market owner Saqib Choubhry, who arrived in the United States 14 years ago from Pakistan, told the governor that “people are scared” since the presidential election, and that his Middle Eastern customers come less often and buy fewer goods.

McAuliffe, who appeared at Dulles International Airport in January to protest the initial executive order banning entry to the United States by travelers from seven Muslim-majority countries, said he believes the restrictions create an unhealthy sense of fear.

But Republicans who control the state legislature have generally praised Trump’s efforts and worked to build upon them. On a party-line vote Wednesday, the state Senate approved a bill, sponsored by Del. Charles Poindexter (R-Franklin), that would prohibit the creation of sanctuary cities.

Despite their opposing positions, Republicans and Democrats both see the issue as a winner with voters in the race for governor of this purple state, even as Democrats accused the GOP of resorting to legislative trickery to force the lieutenant governor to cast a vote on the matter.

The measure initially failed in a 20-20 vote. Northam, who presides over the Senate but only votes when there is a tie, broke the stalemate with a “no” vote. But then Republicans used a parliamentary maneuver to reconsider the matter, and the bill passed, 21-19.

Asked if he had switched his vote in a deliberate effort to force Northam to vote on the contentious issue, Senate Majority Leader Thomas K. Norment (R-James City) simply walked away from reporters.

About 10 minutes after the vote, the campaign of Republican gubernatorial hopeful Ed Gillespie issued a statement blasting Northam.

“Ralph Northam is out-of-step with Virginians who believe that enforcing our nation’s longstanding immigration laws is common sense,” it said.

Two other measures have already cleared the full General Assembly and are awaiting action by the governor: One bill would require nonprofit agencies that relocate immigrants or refugees in Virginia to compile annual reports about who they have helped.

Another piece of legislation prohibits jailers from releasing any undocumented immigrant who is being sought by federal immigration authorities.

But it’s not just those bills that concern immigrant advocates. The ACLU of Virginia also appealed to McAuliffe to not let state police form operating agreements with federal immigration authorities. Such agreements essentially deputize state officers to carry out immigration raids.

That can have a chilling effect in immigrant communities and discourage people from cooperating with routine law enforcement, said the ACLU’s Claire Guthrie Gastanaga.

McAuliffe told the ACLU in a letter last week that he shared those concerns, saying that he would not endorse such agreements “in the absence of any evidence that they will make our communities safer.”

Gastanaga on Wednesday called on McAuliffe to stand by those words.

“We feel our governor has made a commitment,” she said.