In their final tuneup before this weekend's state party convention, the five Democrats running for governor jousted over illegal immigration and casino gambling during a debate Tuesday that also reflected broader philosophical agreements on many issues facing the candidates.

In their final tuneup before this weekend’s state party convention, the five Democrats running for governor jousted over illegal immigration and casino gambling during a debate Tuesday that also reflected broader philosophical agreements on many issues facing the candidates.

Attorney General Martha Coakley, leading in the polls, faced several barbs from her rivals over her previous opposition to driver’s licenses for undocumented immigrants and her office’s decision to disqualify a potential ballot question that would repeal the state’s casino law.

All five candidates also agreed that Massachusetts was on the “right track” after eight years with Gov. Deval Patrick at the helm, but didn’t hesitate to describe issues with the Department of Children and Families, the Health Connector and the rollout of medical marijuana as “fiascos” and management failures of his administration.

The debate was the last matchup between the Democrats running for governor before the nominating convention in Worcester this weekend when one, or maybe more, may fail to win enough support among party insiders to qualify for the ballot. Coakley came into the forum riding high in the polls, even though Grossman is widely expected to win the convention’s delegate vote.

The latest Suffolk University-Boston Herald poll showed Coakley leading Grossman with 44 percent to the treasurer’s 12 percent. The debate, streamed live on the Internet, was moderated by Suffolk University's John Nucci, a former city councilor, and Herald editorial page editor Rachelle Cohen.

“I’m going to make the argument that this state needs a progressive job creator, not a prosecutor as the next governor,” Grossman said after the 90-minute debate.

With the struggles of past attorneys general to ascend to the governor’s office, Grossman seemed to use the word “prosecutor” as a negative to describe his chief rival for the Democratic nomination.

“Martha Coakley is a prosecutor. That’s fundamentally what she is,” Grossman said. Asked to explain what he meant, Grossman said, “She spent her life as a prosecutor. We need a job creator.”

Coakley said she was not paying attention to the poll numbers, and said her career as a prosecutor in Middlesex County and at the state level is not a detriment to her campaign. She noted her fights against bank home foreclosures and challenging the Defense of Marriage Act.

“I’ve always focused on families, people who need voice, people who need someone to speak for them. I’ve done that as a prosecutor, I’ve done it as AG. I will be the voice for people as their governor,” Coakley told reporters.

All five Democrats said they supported Somerville Mayor Joseph Curtatone’s recent decision to sign an executive order limiting the city’s cooperation with the Secure Communities program, which partners local police with federal authorities to hold undocumented immigrants for possible deportation.

“Anyone who is in public safety know that communities have to have trust and faith in their law enforcement, otherwise they will not come forward, whether it’s domestic violence or drugs,” said former homeland security official Juliette Kayyem.

Coakley said the program was designed to help federal authorities remove threats to public safety from communities.

“We know it’s gone far too far,” she said, by targeting many undocumented immigrants with no criminal background.

Grossman described Secure Communities as a “blunt instrument,” but quickly pivoted to knock Coakley for opposing drivers’ licenses for undocumented immigrants, which he called a public safety issue. Coakley has opposed such licenses in the past, but during the campaign said she would be open to the idea because the federal government has failed to enact comprehensive immigration reform.

Both Grossman and Kayyem said they would support drivers’ licenses and in-state tuition rates for undocumented immigrants.

Dr. Donald Berwick, a pediatrician and former Medicare and Medicaid administrator under President Obama, also sought to differentiate himself from the pack with his support for single-payer health care and his opposition to casino gambling.

A Suffolk University poll released Monday showed that only 37 percent of likely voters now support casino gambling in Massachusetts.

“It’s time to backpedal,” Berwick said.

While the other four candidates said they would oppose repeal if the Supreme Judicial Court certifies a question for the November ballot, Berwick said casinos would not only “cannibalize” the Lottery and cost the state jobs but also lead to addiction and medical health problems for the population.

“Frankly, I do not understand why my opponents are not joining me,” Berwick said.

Joseph Avellone, a biopharmaceutical executive, said he fears that “referendum government” can lead to an unstable business environment, and argued for allowing the state’s 2011 law to play out.

Avellone is against a single-payer system, saying it will cost jobs, and opposes indexing the gas tax to inflation, another law that could be repealed in November.

Avellone called the indexing provision included in last year’s transportation financing plan a ”backdoor tax,” though he said he would likely try to make the case to voters in the future for further increases in the gas tax to support investments in public transit and infrastructure.

Grossman said the Legislature in 2013 made a “modest down payment” of $600 million in new revenue to support transportation, but criticized the likely Republican nominee Charlie Baker for opposing gas tax indexing.

“I would challenge Charlie Baker to say where on earth are you going to get the $1 billion we’re going to lose over the next 10 years,” he said.

The candidates also discussed patronage in state government, affordable housing for students, the need for more public transportation, affirmative action, student debt and the possibility of legalizing marijuana. All five candidates said they would prefer to wait and see how the medical marijuana experiment in Massachusetts and the new legalization laws in Washington and Colorado work before deciding on legalized marijuana.

Avellone and Coakley said they would support student loan forgiveness for graduates entering certain professions, while Grossman called for a four-year tuition freeze at public universities and Berwick said making health care affordable will help graduates pay their loans. Several also noted their support for U.S. Sen. Elizabeth Warren’s bill, pushed by the president on Monday, to allow students to refinance their education loans at lower rates.

In a unique twist in addition to presenting questions from Suffolk students and Twitter, the moderators allowed independent Jeff McCormick and Republicans Baker and Mark Fisher to pre-record questions for the Democrats.

While McCormick asked how they would create jobs and Baker asked if Massachusetts was on the right track in light of recent struggles with DCF and the Affordable Care Act website, Fisher pointed to evidence of welfare fraud and illegal immigration as evidence that the state is on track to become “Detroitachusetts.”

Avellone, Berwick and Grossman all touted their private and public sector experience running businesses and large federal agencies, while Kayyem said a governor can lead on job creation by investing in areas like transportation and the maritime industry, while Coakley said she wanted the governor’s office to be a one-stop portal for small business owners to seek help growing their companies.

While all five acknowledged some of the recent let-downs under Patrick’s watch, the Democrats agreed that the most important thing was to recognize mistakes and fix them, not to place blame for problems that inevitably arise under Democrat and Republican administrations.