The clash of ideals was on full display during an Oct. 3 debate hosted by WGBH, when the pair tussled over various issues, including drug addiction and immigration. The duo also divided sharply on the issue of gun rights.

McMahon, a lifelong resident of Cape Cod, argued government gun-control policies rarely reduce violence, but rather take guns out of the hands of law-abiding gun owners and sellers.

“Only legal guns get off the street,” said McMahon, who won the Republican nomination last month after beating Dan Shores of Hingham in the primary election. Healey ran unopposed.

McMahon obtained his law degree from Suffolk University and served in the Army National Guard. With more than three decades of legal experience, McMahon is a member of the Upper Cape Tea Party, a Cape Cod group formed in 2012 that advocates for limited government, individual liberties and fiscal responsibility, according to its website.

Healey, meanwhile, worked for seven years in the state attorney general’s office before she was elected to the top job in 2014. She also worked a stint in the private sector for the legal firm WilmerHale, and became the first openly gay attorney general in the United States. Last November, respondents to a Western New England University Polling Institute poll gave the attorney a 64 percent job approval rating.

McMahon, an ardent supporter of the Second Amendment, was specifically critical of Healey’s 2016 decision to apply the state’s assault rifle ban to “copycat” firearms that operate similarly to well-known brands including the Colt AR-15 and the Kalashnikov AK-47, which were previously banned in 1998.

A federal judge in April upheld Healey’s interpretation and dismissed a legal challenge.

More recently, Healey joined a group of fellow attorneys general and filed an injunction to prevent 3D-printing of guns in Massachusetts, saying it posed a serious public-safety risk.

“It’s probably pretty clear I’m not the NRA’s favorite candidate in this race,” Healey said, noting that the National Rifle Association has already sued her twice.

Beyond guns, Healey and McMahon agreed that the state needs a comprehensive approach to overcome the opioid epidemic in Massachusetts, which on average killed more than three people per day through the first half of 2018, according to state statistics. But the pair disagrees on approach.

Healey in June sued drugmaker Purdue Pharma, claiming more than 670 Massachusetts residents prescribed Purdue opioids died from related overdoses since 2009. She has also headed a multistate investigation into drug trafficking and promotes prevention measures among middle school children.

The state’s top lawyer, however, does acknowledge Massachusetts needs to do more to combat drug abuse.

“We’re not doing enough,” she said. “I’ve long been an advocate for better treatment.”

McMahon, who according to his website lost his eldest son to an opiate addiction, has proposed a multi-pronged approach, including greater public support for privately run long-term treatment centers and greater cooperation with federal agencies, including U.S. Immigration and Customs Enforcement, known as ICE. He said he would also more aggressively police drug dealers and pursue heftier sentences against those convicted.

“I would go after the drug dealers. That’s No. 1,” McMahon said. “Let’s drive these pushers -- these drug purveyors -- let’s drive them out of the state. ... We’re fighting a war.”

The Healey campaign has outspent her opponent. Her campaign at the same time has amassed a sizeable war chest, spending $473,267 and growing its bank account nearly 40 percent to $2.2 million, as of Sept. 15.

The McMahon campaign, meanwhile, spent $82,364 during the same period, and its bank account totaled $4,185.

A supporter of President Donald Trump’s so-called “travel ban” preventing people from several predominantly Muslim countries from entering the United States, McMahon is critical of Healey’s many lawsuits filed against the president and the government over his policies. He’s also accused her of politicizing her position.

The Bourne lawyer opposes sanctuary-city policies, which generally limit cooperation between local agencies and federal immigration officials, and said immigrants with criminal records should be subject to prosecution.

Healey defended her opposition to the travel ban, saying some of her biggest allies in the effort included the state’s largest private-sector and nonprofit employers, which also opposed the “wrong-headed immigration policy.”

When asked about sanctuary cities, however, she was careful with her words.

“I support current laws and local, state and federal officials working together to keeping those who are dangerous to our communities off the street,” she said.

Eli Sherman is an investigative and in-depth reporter at Wicked Local and GateHouse Media. Email him at esherman@wickedlocal.com, or follow him on Twitter @Eli_Sherman.