RICHMOND — Virginia Democrats surged in fundraising over the summer, building a lead over Republicans in total cash reserves heading toward this fall’s crucial legislative elections.

Democratic candidates for the House of Delegates reported a total of $8.6 million cash on hand as of Aug. 31, compared with $7.7 million for Republican House candidates, according to the nonpartisan Virginia Public Access Project.

On the Senate side, Republicans reported a slight overall lead, with $5.3 million on hand compared with $5 million for Democrats.

All 140 seats in the legislature are on the ballot this year, as Republicans defend razor-thin majorities in the House (51-48) and Senate (20-19), with one vacancy in each chamber. With the balance of power up for grabs, Virginia is drawing enormous attention — and money — from national interests in both parties.

The top overall fundraiser for July and August — the two-month period covered by campaign finance reports due at midnight Monday — is a candidate who isn’t even on the ballot. Del. Nicholas J. Freitas (R-Culpeper), who missed deadlines for filing campaign paperwork, posted contributions of $513,000 for his write-in campaign for reelection against Democrat Ann Ridgeway, who raised $30,000. Freitas’s haul included $500,000 from conservative megadonor Richard Uihlein of Wisconsin.

Otherwise, the big money generally flowed to hotly contested seats where Democrats are hoping to make gains. The most expensive race involves House Speaker Kirk Cox (R-Colonial Heights), whose district was among more than two dozen redrawn this year by a federal court seeking to correct for racial gerrymandering. His district, which had favored Republicans by 26 points, now tilts Democratic by six under the new map, according to an analysis by VPAP.

Cox narrowly outraised Democrat Sheila Bynum-Coleman, bringing in $390,00 to her $330,000. She was third in House fundraising, behind Freitas and Cox. Yet Cox, a 29-year veteran and the state’s most powerful Republican, had a hefty advantage in cash on hand — $590,000, compared with Bynum-Coleman’s $341,000.

Both parties found something to crow about in the latest finance numbers.

“Republicans are getting outraised and outworked,” Democratic Party of Virginia spokesman Jacob Rubenstein said. “Their house is on fire.”

Republicans argued that Democrats owed their big-money haul to a few “megadonors” and out-of-state activists, whose small online donations masquerade as local grass-roots support.

“We knew Virginia Democrats would be well funded by millionaires and liberals from California, New York and DC,” Cox spokesman Parker Slaybaugh said in an email. “This reporting period has shown Democrats care more about their big money special interest groups and out of state donors than they care about hard-working families here in Virginia.”

Aside from Cox, the other powerful Republican running in a district remade by the new map is Del. Chris Jones of Suffolk, chairman of the House Appropriations Committee.

Jones, whose remade district greatly favors Democrats, raised $165,000 over the summer and headed into September with $603,000 on hand. His Democratic challenger, Clint Jenkins, did not file a campaign report by the midnight deadline. He had $56,000 on hand on June 30, the end of the previous filing period.

In Northern Virginia, the Democrat vying to replace retiring Sen. Richard H. Black (R-Loudoun) raised more than his GOP rival. Del. John J. Bell (D-Loudoun) took in $207,000, while Republican Geary Higgins raised $118,000. But Republican Del. Tim Hugo (Fairfax), who was nearly unseated two years ago, raised more than his challenger — $297,000 to Democrat Dan Helmer’s $192,000.

A number of Democratic House freshmen from Prince William County who won in a 2017 anti-Trump wave substantially outraised Republican challengers. They include: Jennifer D. Carroll Foy (with $31,000 to Republican Heather Mitchell’s $7,000); Danica A. Roem (with $143,000 to Republican Kelly McGinn’s $86,000); Del. Elizabeth R. Guzman (with $162,000 to Republican D.J. Jordan’s $71,000); and Hala S. Ayala (with $243,000 for a rematch with the Republican she unseated, Rich Anderson, who raised $48,000.)

Fundraising was closer in another rematch, with freshman Del. Wendy Gooditis (D-Clarke) raising $164,000 and the Republican she unseated, Randy Minchew, with $169,000. Freshman Del. Lee J. Carter (D-Manassas) raised $74,000, while his Republican rival, Ian Lovejoy, took in $68,000.

Democrats outraised Republicans in key suburban Senate districts outside Richmond, all longtime GOP strongholds that have turned blue since the election of President Trump. Freshman Del. Debra H. Rodman (D-Henrico), who is trying to unseat Sen. Siobhan S. Dunnavant (R-Henrico), raised $408,000. Dunnavant took in $273,000. Democrat Ghazala Hashmi raised $270,00 for her challenge to Sen. Glen H. Sturtevant Jr. (R-Richmond), whose total was $138,000.

In rural-suburban territory outside Richmond that Democrats consider a stretch, Democrat Amanda Pohl raised $150,000 for her challenge to Sen. Amanda F. Chase (R-Chesterfield), who took in $100,00.

Fundraising mostly favored Democrats in House races overlapping with those Senate districts. Democrat Larry Barnett raised $159,000 for his bid to unseat veteran Del. Roxann L. Robinson (R-Chesterfield), who raised $45,000. Freshman Del. Dawn M. Adams (D-Richmond) took in $87,000 for her race against the GOP’s lone African American recruit, Garrison Coward, who raised $36,000. She had $236,000 on hand to his $23,000. Another freshman, Del. Schuyler T. VanValkenburg (D-Henrico), raised $170,000, compared with $110,000 for Republican challenger GayDonna Vandergriff.

One exception was Republican Mary Margaret Kastelberg, who is running for the seat being vacated by Rodman. She outraised Democrat Rodney Willett $163,000 to $100,000.

In Virginia Beach, another big battleground this year, fundraising for two Republican-held Senate seats is close: Sen. William R. DeSteph (R) raised about $175,000 and had about $261,000 on hand, while Democratic challenger Missy Cotter Smasal raised almost $241,000 and had $285,000 in cash.

The candidates vying to succeed retiring Sen. Frank W. Wagner (R-Virginia Beach) were about even. Democrat Cheryl B. Turpin, looking to make the jump from the House seat she won two years ago, raised $222,000 and had almost $261,000 on hand. Republican Jen Kiggans raised $271,000 and had $266,000 in cash.

Democrats have a cash advantage in three House seats at the top of their list for flipping from red to blue.

In Newport News, Democrat Shelly Simonds outraised Republican incumbent David E. Yancey, $216,000 to $72,000. The gap is not as stark in cash on hand: Simonds had $346,000 in the bank, while Yancey had $291,000.

Their race is a rematch of one that was a tie two years ago; Yan­cey won when his name was selected in a random drawing. The new map has made the district bluer, according to VPAP’s analysis.

Nearby in Hampton, Democrat Martha Mugler raised nearly $211,000 compared with $47,000 for Republican Colleen Holcomb. They’re running for an open seat that had been held by a Republican.

In Stafford County, Democrat Joshua Cole raised $189,000, while Republican Paul Milde brought in less than $51,000. Cole ran for the seat two years ago and lost by just 73 votes to now-Del. Robert M. Thomas Jr. (R-Stafford). Thomas lost a primary this year to Milde.