Virginia Governor Terry McAuliffe (D), left, greets Jeremy McPike, Democratic candidate for Virginia's 29th Senate District, as they gather with campaign workers for a brief election day rally at the home of Manassas Park Council Member Jeanette Rishell on Nov. 3. (Jahi Chikwendiu/The Washington Post)

Spanish-language political ads airing just before last week’s state and local elections in Virginia carried an urgent message about a candidate who wasn’t even on the ballot: Republican presidential contender Donald Trump.

“Because Trump isn’t the only one,” a mother says to her daughter, in Spanish, urging her to vote for candidates who oppose Trump’s vitriol against undocumented immigrants. “The Republicans of Virginia have proposed to track immigrants as if they were packages and have compared us to rats.”

The ad — by a group co-founded by television legend Norman Lear, with actor Alec Baldwin and civil rights leader Dolores Huerta on its board — was part of a broader strategy to mobilize Latino voters in Virginia last Tuesday and in 2016, when Virginia is expected to play a key role in choosing the country’s next president.

Given the commonwealth’s growing Latino population and its perpetual status as a swing state in national elections, “the Latino vote in Virginia could really decide the direction of this country in the years ahead,” said Randy Borntrager, political director of People for the American Way, the Washington-based group behind the Trump ad.

The ad was part of a multi-pronged effort last week targeting specific constituencies, including the working poor, business groups, unions and other ethnic groups. Advocates fell short in their goal of winning Democratic control of the state Senate but won key victories that they say could bode well for their goals for the future.

Working with the state Democratic Party, the Latino campaign focused mostly on Prince William County, where since 2000 the Spanish-speaking population has more than tripled, to about 98,100.

There, Jeremy McPike (D) was locked in a close race with Manassas Mayor Harry J. “Hal” Parrish II (R) for the 29th District state Senate seat that includes Manassas, Woodbridge and other areas with large Latino communities. McPike won with 54 percent of the vote.

McPike’s platform included support for a Virginia policy that allows students who were brought into the country illegally by their parents to pay in-state tuition to attend public colleges and universities. That program could be affected by the outcome of the 2016 presidential election, because Republicans have called for canceling a federal program that allows those students temporary legal immigrant status.

McPike’s campaign said a key factor in his victory was strong Latino turnout, fueled by door-knocking and rallies that featured appearances by Huerta — co-founder of California’s United Farm Workers union with Cesar Chavez in the 1960s. Noah Kim, McPike’s campaign manager, estimated that about 20 percent of the district’s nearly 113,000 registered voters are Latino.

“This is obviously a very large voting bloc in the 29th Senate district,” Kim said.

A separate effort targeting Republican Corey A. Stewart — the longtime chairman of the Prince William Board of County Supervisors — did not succeed in ousting the incumbent but may have helped turn out voters for McPike.

In that campaign, volunteers with Maryland-based Casa in Action reminded voters that Stewart was behind a 2007 county law requiring Prince William police to check the immigration status of anyone arrested. The practice has led to scores of deportations that have damaged mixed-status families in the Latino community, advocates for immigrants say.

Stewart survived the attack, beating Democratic challenger Rick Smith with 57 percent of the nearly 66,700 votes cast. But the effort energized Latino voters, said Kim Propeack, director of Casa in Action. “It was really extraordinarily exciting to see all these bustling, robust, stable neighborhoods where there was a lot of excitement about the election,” Propeack said.

Casa in Action also helped boost voter turnout in Fairfax County, where two Democratic candidates beat Republicans for open seats. In those races, both of the Republican candidates were Latino. But Casa in Action worked on behalf of their Democratic opponents, because those were the candidates they thought would better serve the Latino population.

“We kind of felt like we had a particular responsibility to get engaged in these races where there were Latino Republicans that are not good on our issues, like minimum wage,” Propeack said.

Jennifer Boysko (D) defeated Raul “Danny” Vargas (R) to take the seat being vacated by state Del. Thomas Davis Rust (R-Fairfax) in the 86th District. And school board member Kathy Smith (D) beat John Guevara (R) to take the supervisor’s seat being vacated by Michael R. Frey (R-Sully).

Casa in Action — which also helped mobilize Latino voters in Arlington County — plans to ramp up its efforts for next year’s presidential elections, Propeack said.

Meanwhile, Republicans are also trying to gain ground with Latino voters. John Whitbeck, chairman of the Republican Party of Virginia, said candidates targeted Latino business leaders and neighborhood groups across the region.

The strategy “was very effective in terms of talking to people who don’t necessarily vote Republican or Democrat; they’re just sort of folks that like to hear from candidates,” Whitbeck said. Both parties say they want to recruit more Latino candidates to run for office, a way to connect with voters who want candidates that share their backgrounds.

In Fairfax last week, Dalia Palchik — whose family is from Argentina — became the county’s only Latina school board member. She said voters in the heavily Latino Annandale neighborhood were happy to hear her speak to them in Spanish about her desire to bring more diversity to the ranks of teachers in Fairfax schools. She won 58 percent of the vote in the county’s Providence District, beating incumbent Patty Reed.

“It was like being a local celebrity,” Palchik said. “They were so ecstatic. The big thing is not just that they’re registered to vote, but that they have a reason to vote.”