Tom Perriello, left, shakes hands with Lt. Gov. Ralph Northam at the start of the first debate of Virginia's Democratic candidates for governor at Lanier Middle School in Fairfax. (Sarah L. Voisin/AP)

Lt. Gov. Ralph Northam and former congressman Tom Perriello, locked in a neck-and-neck battle for the Democratic nomination to be Virginia’s governor, saved their harshest words for President Trump over the weekend, making their first primary debate a largely positive, gentlemanly affair.

Northam and Perriello generally agreed on policy and exchanged only a few, gentle jabs during the hour-long forum moderated by NBC4 reporter Tom Sherwood. Saturday’s debate, the first of five, was held in Fairfax County — important territory in voter-rich Northern Virginia.

Offered a chance to rebut Northam’s assertion that Virginians should have greater priority in admission to public colleges and universities, compared with out-of-state students, Perriello said, “I would just take 30 seconds back to agree.”

Perriello, who upset Virginia’s Democratic establishment with his unexpected entry into the race in January, took pains to several times praise term-limited Gov. Terry McAuliffe (D), who is backing Northam.

“I think McAuliffe has done a tremendous job,” Perriello said in response to a question about whether this is a “change election.”

Yet Perriello also suggested he would do more to address the state’s opioid crisis, revamp its “regressive criminal code,” and raise the minimum wage, which he called a “poverty wage” in pricey Northern Virginia.

“So, no, I’m not satisfied with the status quo,” he said.

Sometimes knocked as too low-key, Northam was loose and lively. He left his spot on the stage at one point, after Sherwood forgot to give him a crack at a question, to playfully mark up the moderator’s notes as a teacher might correct a student’s paper.

While amiable all night, the lieutenant governor still asserted his liberal bona fides — and questioned Perriello’s with a few digs about the former congressman’s receipt of “dark money” from a political group that does not identify most of its donors, his past support for the National Rifle Association and his mixed record on abortion rights.

“I am the only statewide elected official over the years that has been outspoken against offshore drilling,” Northam said. “I have opposed fracking. . . . I have been against uranium mining.”

Sherwood gave each candidate the opportunity to ask the other a question — something Perriello said caught him off guard. He went first, with a softball: “The question I would ask is: What do you think you have learned most from your great service as lieutenant governor?”

When Northam was up, he lobbed something harder. He asked Perriello why he took campaign contributions from the NRA while in Congress, noting that it was after the 2007 mass shooting at Virginia Tech.

Perriello, who got an “A” rating from the NRA when he ran for Congress, noted he is no longer in the group’s good graces. “I called them a ‘nut-job, extremist organization’ and compared them to the John Birch Society,” he said. “I don’t imagine those checks are in the mail.”

Northam, 57, is a pediatric neurologist from the Eastern Shore who graduated from the Virginia Military Institute and, as an Army major, treated wounded soldiers during Operation Desert Storm. He said that he grew up with an appreciation of hunting but that, after treating toddlers injured by guns, he knew that “assault weapons have no place on our streets.”

He also spoke about taking on the tobacco industry as a legislator when he pushed through the state’s ban on smoking in restaurants, and how he skewered Republican efforts to require women to get a transvaginal ultrasound before obtaining an abortion.

Perriello, 42, grew up outside Charlottesville and got his undergraduate and law degrees from Yale. He won election to Congress in 2008. During his single term, he won stature within the party for supporting the Affordable Care Act despite his conservative district. He lost reelection in the tea party wave of 2010, in part because of his support for the health-care law — something that endeared him to President Obama.

But Perriello also has drawn fire from liberals for advocating an amendment to the ACA that would have prevented federal subsidies for insurance plans that cover abortion. Asked by Sherwood about abortion, Perriello made no mention of his past. Instead, he presented himself as a strong advocate for abortion rights and also said abortion services should be made more accessible, noting some places around the state lack clinics.

Perriello has sworn off donations from Dominion Power — the state’s largest utility and largest political donor — and opposes two oil and natural gas pipelines planned for rural Virginia. Northam has not taken a position on the pipelines, which McAuliffe has touted as a source of jobs, but says they must be subjected to strict environmental review.

One of the sharpest exchanges of the night came after Northam said he had sent letter to state environmental officials, pressing them to make the pipeline review process more transparent. Perriello asked Northam if he had discussed the letter beforehand with Dominion.

“I’m not going to stand here on the witness stand,” Northam replied. “It’s not a ‘yes’ or ‘no,’ or us versus them.”

Perriello repeated his call for publicly financed campaigns. Northam said he favors comprehensive campaign finance reform.

The debate did not dwell on Trump, but Perriello framed his bid as a means of resisting the president in a closing statement so fiery that Sherwood responded with, “Pass the collection plate.”

“Just a few months ago, most of us were busy crying,” Perriello said to laughs. “We were paralyzed. We didn’t know what had become of a country that had elected a person who had run the most overtly racist campaign of my lifetime. . . . But all of you, and millions of others across the country, decided to get up off our couch and organize and resist.”

He continued: “I have pledged to, within the limits of the law, to have noncompliance with any acts of the Trump administration that are unconstitutional and unconscionable in nature.”

Northam, while vowing to “stand up to the narcissistic maniac on the other side of the Potomac,” mostly went for the soft sell.

“As a pediatrician, I have held a lot of babies in my arms,” he said. “And when you look into the eyes of a baby, you know, you don’t see the hatred and the bigotry that we so often see in society. And our question — as a society, as Virginians — is, what are these babies going to grow up to be? . . . Are they going to have access to a world-class education system? Are they going to have access to affordable health care? And are they going to live in environments where the air and the water are clean?”

There was no real discussion of the three Republicans running for governor, but Perriello criticized the front-runner, former Republican National Committee chairman Ed Gillespie, for not speaking out against Trump’s entry ban on travelers from predominantly Muslim countries.

Gillespie faces Prince William County Supervisors Chairman Corey A. Stewart and state Sen. Frank W. Wagner (Virginia Beach) in the GOP’s June 13 primary. The general election takes place Nov. 7.