In the first debate of Virginia’s general election campaign, candidates vying to become the state’s next attorney general on Saturday outlinedstark differences in how they would approach the office, sparring over gun control, same-sex marriage and abortion rights.

The exchange was at times contentious as the Democratic nominee, state Sen. Mark R. Herring of Loudoun, said his Republican opponent, state Sen. Mark D. Obenshain of Harrisonburg, would view the job “through a prism of radical extremism.”

Herring sought to align Obenshain with Attorney General Ken Cuccinelli II, the GOP gubernatorial nominee, and to Republican lieutenant governor nominee E.W. Jackson. Herring told the audience that he and Obenshain “could not be more far apart” ideologically.

Obenshain appeared surprised by the attacks but pushed back, saying Herring would try to interject his own politics into the office.

“Our responsibility as attorney general is to step up and not be the lawmaker, not be a federal judge,” Obenshain said. “We are charged with making sure we defend, where appropriate, state laws.”

Aside from their roles as senators and their first names, the candidates appeared to have little in common during the hour-long debate sponsored by the Young Lawyers Conference at the Cavalier Hotel.

The attorney general’s office is an important one in Virginia politics as one of three statewide posts that frequently has been a launching pad for a gubernatorial bid or other higher offices. A Democrat has not won the attorney general’s seat in 20 years.

Herring is running on the Democratic ticket with gubernatorial nominee Terry McAuliffe and lieutenant governor candidate state Sen. Ralph S. Northam of Norfolk.

On a question of stricter gun laws in the wake of the elementary school shootings in Newtown, Conn., Herring said he supports expanding background checks. He accused Obenshain of being “consistently opposed” to them — a charge Obenshain denied.

“We need to make sure guns are out of the hands of those that should not have them,” Obenshain said. “But imposing further restrictions on law-abiding citizens is not the solution.”

Herring called Obenshain’s response “an excuse.”

“We need to close the gun-show loophole,” Herring said. “You’ve been consistently opposed to that. You’re standing in the way.”

On the issue of same-sex marriage, Obenshain accused Herring of changing his stance for political reasons and not on principle. Both candidates voted for an amendment in 2006 that defined marriage as between a man and a woman.

“Almost eight years ago I did vote that way,” Herring said. “But you know what? Since that time, I’ve talked to my friends, my constituents, talked to co-workers, talked to my family. And like millions of Americans and a lot of Virginians, I don’t believe that way anymore. So I support marriage equality.”

Obenshain said he continues to oppose same-sex marriage based on his faith.

“It’s easy to stand up now and say I stand for something else,” Obenshain said. “We both voted for it. . . . I guess we are entitled to change those opinions on the basis of which office we’re seeking.”

On transportation, Herring aimed to cast himself as someone willing to work across the aisle. He touted his vote in favor of a landmark transportation funding overhaul championed by Gov. Robert F. McDonnell (R) during this year’s General Assembly.

Obenshain, many other Republicans and some Democrats voted against the legislation, calling it a tax hike and an unfair burden on citizens.

As attorney general, Cuccinelli played a role in the bill’s eventual outcome. He weighed in at the end of the process to say the legislation was unconstitutional, but offered suggestions for how to fix it that were part of the final compromise.

Obenshain said he agrees that transportation funding is a priority, but differs on how to solve the problem.

“I know there are those who believe there are no problems for which higher taxes are not the solution,”Obenshain said. “The big question is how was the money going to be raised, not whether we needed it.”

The candidates also clashed over tighter restrictions imposed on women’s health-care clinics that offer abortions. The rules were passed by the General Assembly and approved by the state Department of Health.

Herring said that if he were elected he would seek to challenge the restrictions. “It was done solely because of some of the procedures done in those clinics,” said Herring, referring to abortions.

Obenshain said the measures are meant to make women’s health care safer.

Herring also took aim at Obenshain’s campaign theme of preserving and expanding personal freedom for Virginians, a message Obenshain said he inherited from his father, Richard D. Obenshain, seen as the architect of the modern conservative movement in the state. He was killed in a plane crash in 1978 while running for the U.S. Senate.

Herring said that message does not square with Obenshain’s record on women’s health care, noting a bill Obenshain sponsored that would have required women to report a miscarriage to the police.

Throughout the debate, Herring repeatedly sought to tie Obenshain to his Republican running mates.

“You’ve heard a lot about the fiery rhetoric of E.W. Jackson,” Herring said, referring to controversial statements by the Chesapeake minister about gay people and abortion. Obenshain “has been able to put that radical ideology to work in committee, in legislation and in votes on the Senate floor.”

Obenshain pushed back, challenging Herring’s campaign theme that he would take politics out of the attorney general’s office.

“Until three minutes ago, I was really looking forward to traveling the state with Mark,” said Obenshain. “Virginians . . . do not want to hear us travel the state and reignite culture wars.”