After an election marked by competitive races and slim margins of victory, change is coming to some of the most contested districts of the Virginia House of Delegates.

In Loudoun County, residents of the House’s 33rd District will have a new representative for the first time in 20 years: Republican Dave LaRock, who had unseated longtime incumbent Del. Joe T. May in an upset in the GOP primary, defeated his Democrat challenger Mary Costello Daniel in Tuesday’s general election.

LaRock will be joined in Richmond by Democrat Michael Futrell, a pharmaceutical salesman and founder of a nonprofit organization. Futrell defeated Del. L. Mark Dudenhefer (R) in the House’s 2nd District, a territory that stretches from northern Stafford County through Dale City in Prince William County.

The two races demonstrate that in Loudoun and Prince William, two of Northern Virginia’s politically evolving, bellwether jurisdictions, elections are anything but predictable. Loudoun residents were stunned by LaRock’s primary victory over May, a widely respected veteran legislator, giving Democrats hope for victory in the general election. In Prince William, voters defied expectations by electing Futrell, who triumphed despite criticism of his nonprofit group and a campaign that was vastly outspent by Dudenhefer’s.

LaRock’s victory — he received about 13,800 votes; Daniel got about 11,000 — wasn’t nearly as close as other races in Northern Virginia. But the sprawling district, which includes much of western Loudoun, consistently leans Republican. Although she lost, the fact that Daniel pulled in as many votes as she did was applauded by Democrats.

“I am really proud of our campaign and the job we did promoting a sensible, bipartisan approach to state government,” Daniel said in a statement. “We had tremendous support throughout the district . . . and I was received well everywhere I went. . . . I am honored that so many people voted for me.”

As with other campaigns across Virginia, the race in the 33rd District was marked by heated attacks centered on social issues, as well as the economy and transportation. In the weeks before the election, Daniel assaulted LaRock’s hard-line views on abortion, especially.

In his victory statement, LaRock focused on less partisan issues. He said he would go to Richmond committed to “finding ways to make our state budget leaner, improve our roads and strengthen our businesses. We can and must accomplish these goals while looking out for the most vulnerable and needy in our community.”

LaRock said he would also focus on avoiding tax increases.

“These goals aren’t unique to the Republican Party; they’re something we can all get behind,” he said in the statement. “I intend to rise above labels and parties, bringing progress to our district at a time when folks are fed up with dysfunctional government.”

With a particularly contentious gubernatorial battle overshadowing the General Assembly races, many voters interviewed at polls across Loudoun and Prince William on Election Day said they weren’t as familiar with the candidates running for state office. Most said they voted in along party lines.

In the 2nd District race, that was enough to help Futrell upset Dudenhefer by carrying Democratic-leaning, heavily populated Prince William precincts. Dudenhefer won every precinct in Stafford, but Futrell claimed all but two precincts in Prince William, winning most by a ratio of more than two-to-one, according to Virginia Public Access Project records.

Despite lingering controversies during the campaign, including criticism that Futrell’s nonprofit organization lost its tax-exempt status in May for failure to file tax returns for three years — Futrell was able to narrowly defeat Dudenhefer with 50.7 percent of the vote, or by 224 votes, state election results show.

About a dozen voters interviewed at Prince William polling precincts said that they had never heard of Futrell but that they voted only for Democrats.

Harry Wiggins, chairman of the Prince William Democratic Committee, said that when more people vote in those precincts, Democrats tend to do well. Enough voted Tuesday to propel [Terry] McAuliffe and Futrell to victory.

“Everybody’s going to know who [Ken] Cuccinelli and McAuliffe [are],” he said. The strategy was simple but effective, Wiggins said: providing sample ballots, which were handed out at the polls by both parties Tuesday, to tell voters what the party supports.

“These sample ballots are so critical,” he said.

Wiggins said that frustration with Cuccinelli and the tea party faction with which he is associated drove many to the polls who don’t usually vote in off-year elections.

Republicans “ran the most extreme candidate they could possibly run,” Wiggins said. “That certainly helped.”

But Republicans persevered in other tight races across the two counties. In another closely watched race that spanned Loudoun and Prince William, Republican Del. David I. Ramadan kept his seat by just 195 votes over Democrat John Bell in the 87th District, according to state election results. It was a narrow margin of victory, but less so than Ramadan’s first election victory in 2011, which he got with just 51 votes.

In the 13th District in Prince William, Republican Del. Robert G. “Bob” Marshall persevered after Democrat Atif Quarni fell short of an upset by fewer than 500 votes.

Aside from some problems with computerized poll books at some Loudoun precincts that resulted in a slower check-in process but did not affect the votes, election officials in Loudoun and Prince William said Election Day operations proceeded smoothly and without disruption.