Gov. Terry McAuliffe (D-Va.), along state senate candidate Jeremy McPike (D), rallied volunteers in Manassas Park as voters headed to the polls Tuesday. (Arelis Hernandez/The Washington Post)

Republicans held onto the Virginia Senate in fiercely contested elections Tuesday, leaving Gov. Terry McAuliffe without legislative leverage or political momentum as he works to deliver Virginia for his friend and ally Hillary Rodham Clinton in 2016.

The outcome was a blunt rebuke to McAuliffe (D), who had barnstormed the state with 24 events over the past four days and who portrayed the elections as a make-or-break moment for his progressive agenda.

All 140 seats in the General Assembly were on the ballot. But all eyes were on a handful of Senate seats that would decide whether Republicans held their 21-19 majority in Richmond’s upper chamber. Because the GOP dominates the House, flipping the Senate was the term-limited governor’s only hope for building a legislative legacy.

Democrats could have taken control by picking up just one seat because of the tie-breaking authority of Lt. Gov. Ralph Northam (D). But Republicans held all of their seats.

“Today, Virginians voted for a fiscally responsible and conservative majority,” Senate Majority Leader Thomas K. Norment (R-James City) said Tuesday. “Our victory is all the more impressive in that it was achieved despite the record-breaking millions of dollars spent by Governor McAuliffe, his allies and out-of-state PACs. This election was decided by Virginians.”

See the full results for statewide and local races.

Senate Minority Leader Richard L. Saslaw (D-Fairfax), meanwhile, held out hope that the results could change. He said he suspected irregularities in a Richmond-area race won by the GOP because Republican turnout was so heavy.

“There may be some irregularities going on in Powhatan County,” he said. As of late Tuesday night, Democrat Dan Gecker had not conceded to his opponent, Glen Sturtevant.

The governor hinted that the vote counting wasn’t over. “We should ensure that all of the votes are counted, but I am confident that every man and woman elected tonight will come to Richmond ready to join our bipartisan efforts to build a new Virginia economy,” McAuliffe said in a statement Tuesday.

Bob Holsworth, a former Virginia Commonwealth University political scientist, called the results “a fairly bitter defeat for the governor,” noting that he had solicited millions from out-of-state donors to help bankroll races.

“Having said that, he’s a person of remarkable resilience,” Holsworth added. “He’s not the kind of guy who gets depressed by some defeat. He’ll move on to some Plan B to carve out a legacy on economic development and some agreement with Republicans on education, while he knows he will not get the Medicaid expansion that he so wants.”

Having one chamber on McAuliffe’s side could have, at least in theory, led to the sort of bipartisan deal-making that allowed then-Gov. Mark R. Warner (D) to pull off a record tax hike in 2004. But Warner could appeal to a host of moderate Senate Republicans and a more closely divided House. McAuliffe faces a more conservative Senate Republican caucus and a House with a wide GOP majority.

For that reason, the biggest prize the elections offered was momentum — the opportunity for the winning party to claim that voters in this key presidential swing state were leaning its way one year ahead of the White House contest.

McAuliffe, once a record-smashing fundraiser for his close friends Bill and Hillary Clinton, had hoped a win would help sway purple Virginia in 2016.

National donors and outside groups on the left and right seized on the state Senate races. A gun-control group backed by former New York Mayor Michael R. Bloomberg pumped more than $2.3 million into the two most hotly contested Senate races, one in Northern Virginia, the other in the Richmond suburbs. Donating in smaller amounts were the Koch brothers’ Americans for Prosperity, the National Rifle Association and the Republican State Leadership Committee.

Republicans and Democrats alike went into Tuesday predicting success. But mere hours after the polls opened on Election Day, the Democratic Party of Virginia struck a surprising tone: Don’t be surprised if we lose.

The party sent out a two-page memo to reporters laying out reasons why this might not be its year. It noted that Republicans tend to vote in off-year elections such as this one, that Democrats are playing in traditionally Republican districts and that money has flowed in from outside groups.

“The 2015 election has always been an uphill battle for Democrats; off-­off-­off-year elections are not traditionally friendly ground for a party that relies on high turnout numbers for success,” the Democrats’ communications office wrote.

In recent years, Democrats have effectively used data to turn out voters for statewide and national races, but in the memo they acknowledged that those voters tend to stay home for local races.

“While our unprecedented field and targeting programs have helped, all data shows that likely voters this election are still much more Republican,” the memo says.

Fatigue from a seventh year of the Obama White House hurts even more, Democrats said.

The two most hotly contested races were for seats being vacated by two of the Senate’s last moderates, both of whom are retiring: Sen. Charles J. Colgan (D-Prince William) and Sen. John C. Watkins (R-Powhatan).

Democrat Jeremy McPike, a volunteer firefighter, beat Manassas Mayor Harry J. “Hal” Parrish II (R) for Colgan’s seat. According to unofficial results Tuesday night, Republican Sturtevant, a school board member, defeated Democrat Gecker, a Chesterfield County supervisor, for Watkins’s seat.

“Gun laws really have to be changed,” Rebecca Neiss said after casting her vote for McPike with two daughters in tow.

Parrish, the Manassas mayor, opposes Medicaid expansion, has an A-minus rating from the NRA and cast the tie-breaking vote allowing restrictions on Manassas abortion clinics. McPike, who works for the city of Alexandria, favors Medicaid expansion, gun control and abortion rights.

The August shootings of two journalists in southwest Virginia turned gun control into a key issue in the races, as McAuliffe pushed for tighter restrictions on firearms purchases, with the support of Andy Parker, the father of one of the victims.

In Loudoun County, Democrat Jill McCabe, a pediatric emergency-room doctor, failed to unseat Sen. Richard H. Black, a former Marine combat pilot and lawyer who is among the Assembly’s most conservative members.

Democrats conceded that unseating Black would be as difficult as their quest to oust incumbent Republican Frank W. Wagner in Virginia Beach. Wagner withstood a challenge from Democrat Gary McCollum.

Wagner, the former owner of a ship repair company, seemed vulnerable after reports that he took gifts from special interests and sponsored legislation friendly to Dominion Virginia Power. But McCollum was stung by revelations that he misrepresented his military record.

Nearby, Sen. Lynwood W. Lewis Jr. (D-Accomack) successfully defended a seat he won by just 11 votes last year in a special election. His challenger was Republican Richard H. Ottinger.

In southwest Virginia, Sen. John S. Edwards (D-Roanoke) prevailed in a three-way race against Republican Nancy Dye and Democrat-turned-independent Don Caldwell.

Along with gun control, highway tolls came to dominate races in Northern Virginia late in the campaign. Republicans blasted McAuliffe’s plan to turn parts of Interstate 66 into a toll road for some commuters during peak hours. Democratic candidates said they opposed it as well, but the GOP contended that they could not be trusted to buck a governor of their own party once in office. They used the attacks against Del. Kathleen Murphy (D-Fairfax) and Democratic state delegate candidates John Bell and Jennifer Boysko.

Meanwhile in the House of Delegates, in preliminary returns, Republicans appeared to narrowly lose their veto-proof majority, but they still maintained a huge advantage over Democrats in the polarized chamber.

House Democrats picked up two seats in districts formerly held by Republicans who did not seek reelection. Boysko defeated businessman Danny Vargas (R) for Del. Thomas Davis Rust’s (R-Fairfax) seat. Bell defeated Republican Chuong Nguyen for the seat held by David I. Ramadan (R-Loudoun).

Late Tuesday, Murphy was embroiled in a tight race with Craig Parisot, the Republican she narrowly defeated in a special election last year. This time around, less than 200 votes separated the candidates, with absentee ballots yet to be counted.

Fairfax County officials said that they will recheck the totals for Murphy and Parisot on Wednesday to see whether a recount is warranted.

Late Tuesday, Republican Mark Dudenhefer was leading Democrat Josh King to take back the seat he held for one term before losing it to Michael T. Futrell (D-Prince William).

Arelis R. Hernández contributed to this report.