State Sen. Jill Vogel (R), left, and Democrat Justin Fairfax, right, competed against each other for lieutenant governor of Virginia. (Bill O'Leary and Linda Davidson/The Washington Post)

Virginia Democrats Justin Fairfax and Mark Herring on Tuesday won hotly contested races for lieutenant governor and attorney general, respectively, beating back strong challenges from two conservative Republicans and completing a sweep by their party at the top of the ticket.

Fairfax, an Annandale attorney and former federal prosecutor, is the second African American to be elected statewide in Virginia, after L. Douglas Wilder, who served as lieutenant governor and then governor from 1986 to 1994.

He beat state Sen. Jill Holtzman Vogel (R-Fauquier), who embraced President Trump throughout her campaign and staked out strongly conservative positions on guns, abortion rights and the economy.

“This election showed that Virginians believe in our unified vision for the Commonwealth, not one based on fear-mongering and division,” Fairfax, 38, said in a statement. “That positive vision is the one we’ll go to Richmond with — and the one that we’re going to spend the next four years making a reality.”

Herring, who won his first term as attorney general by 165 votes four years ago and took an aggressively progressive posture once in office, defeated Republican John Adams, a former federal prosecutor and clerk to Supreme Court Justice Clarence Thomas.

“The voters looked at the results of 2016 and said we need to set the ship right,” Herring said Tuesday night, after Democratic Lt. Gov. Ralph Northam won the governor’s race and the party appeared to be doing well in multiple state legislative contests. “Today, Virginians said, ‘This is the way back.’ ”

Northern Virginia voters who braved cold and rainy weather to come to the polls Tuesday said they wanted to send a message with their votes.

“Herring is a hero to me because he supported gay rights and women’s rights,” said Nancy Gregory, 64, a librarian who voted at Tuckahoe Elementary School in liberal Arlington with her husband Colt, 66. “We’ve got a gay son and an adult daughter, and we really, really hope Virginia is smart about this election.”

Neither the lieutenant governor’s race nor the attorney general’s contest drew the white-hot attention of the Virginia gubernatorial battle this year, but both were intense, hard-fought affairs.

The part-time lieutenant governor’s job comes with two major positives: In case of a tie in the state Senate, the lieutenant governor can cast a ballot. Additionally, the No. 2 job positions a politician for a run for higher office.

Fairfax, who surprised Democrats by coming within three percentage points of defeating Herring in the primary for attorney general in 2013, said he wants to get Virginians into middle-skill jobs, lower student interest rates and expand Medicaid, an effort that has been stopped over the past four years by the Republican majority in the General Assembly.

Virginia election results 2017: Live maps, analysis, complete updates

He suffered an insult from his own party this fall when his name was omitted from about 1,000 pieces of Democratic campaign literature produced for the Laborers' International Union of North America, which did not endorse Fairfax because he was critical of two proposed natural gas pipelines that the union supports.

In her concession speech Tuesday night, Vogel, 47, did not congratulate Fairfax or mention his name, instead saying, “It’s not always about winning or losing, it’s about making your campaign mean something. We ran a campaign of integrity.”

Vogel, who is managing partner of a 13-attorney law firm, gained notoriety in 2012 for a bill she proposed that originally would have required most women seeking abortions to first undergo a vaginal ultrasound and be offered a view of the fetus — a bill that Fairfax said made the commonwealth a national "laughingstock."

Among other things, Vogel and Fairfax clashed over the issue of Confederate monuments. Fairfax said he personally supports removing monuments, but believes localities should make the decision, and thinks resources could be better directed toward dismantling other “barriers” to racial equality.

Vogel has hammered Fairfax for calling the statues divisive and harmful, a message she has underlined at appearances before white, rural voters in southwest Virginia.

She raised $3.7 million for the race through the end of October, just less than Fairfax’s $3.9 million. More than one-third of Vogel’s money came from her father, William B. Holtzman, founder of Holtzman Oil.

Far more expensive, and just as politically polarized, was the campaign for attorney general, with millions of dollars of donations poured into the candidates' coffers by each party's association of attorneys general.

Money came from interest groups at both ends of the political spectrum. From the right, the Judicial Crisis Network, perhaps best known for its efforts last year to block President Barack Obama's Supreme Court nominee, Merrick Garland, gave $2.35 million. From the left, Everytown for Gun Safety, founded in part by former New York mayor Michael Bloomberg, gave $600,000.

Herring, who has sued the Trump administration over its travel ban and its decision to end federal subsidies to health insurers, warned during the campaign that Adams sought to become “the lawyer for the Republican caucus in Richmond.”

Early in his first term, Herring refused to defend Virginia’s same-sex marriage ban and joined the side challenging that ban. In his assessment, he said, the law was unconstitutional and on the wrong side of history; Adams said Herring’s decision was an indefensible abandonment of the office’s responsibility to defend state law.

Herring also touted his record on reducing the state’s backlog of untested rape kits, cracking down on gangs and leading a Medicaid fraud unit.

Adams said he entered the race because he thinks Herring has turned the top legal office in the state into a partisan political operation.

A conservative who opposes same-sex marriage and abortion, Adams said he would not let his beliefs affect his legal decisions or advice. Adams twice represented clients in Supreme Court cases who objected to requirements that employers provide and pay for contraceptive insurance coverage for their employees.

He and Herring differed on gun control, labor union rights, immigration and most hot-button topics.