Democratic gubernatorial candidates Jay Gonzalez and Robert Massie took aim each other in an attempt to differentiate themselves during a contentious debate on Greater Boston Thursday.

Throughout the debate, Massie and Gonzalez rarely differed when it came to policy priorities but diverged when it came to how they viewed working with the Democratic-controlled legislature.

“The Democrats are out of touch with what’s going around, and I’ll say that as someone who admires many of the people on the legislature,” Massie told moderator Jim Braude. “But here’s the reality: The Democratic party needs to open up, it needs to grow, it needs to be in touch with its younger members, it needs to be in touch with the millions of people who are hurting in this state and not playing games and enabling the governor.”

Gonzalez differed slightly, saying the he didn’t think the legislature was out of touch, but “needed to be pushed.”

“Right now, we have a governor who isn’t asking them to do anything,” said Gonzalez, who served as the state’s budget chief under Gov. Deval Patrick. “If there’s a governor who’s providing leadership and some healthy tension, working in collaboration with the legislature and other stakeholders, we could get big things done and we have to.”

During his four years in office, Baker and legislative leaders have successfully passed laws concerning the opioid epidemic — something his administration has made a key issue. However, the legislative session ended without progress on key issues including the formula for education spending and health care pricing.

When the topic turned the troubles plaguing the state’s transportation system, both largely agreed more funding and targeted actions were required, such as building a rail link between North and South Stations in Boston and firing Kelois, the operator of the state’s commuter rail.

“Charlie Baker is picking the fruit off the trees that we seeded,” Gonzalez said, arguing that his former boss deserved the credit for investing in new train cars for the MBTA. He added that, if elected, he would invest more in the system through asking the wealthy to pay more.

Massie, for his part, took credit for being the first to say he would fire Kelois and said the state needs to lay the ground work for high speed rail. Massie said the cost for that investment would be in the “billions” but would be spread out over ten years, under his leadership.

Throughout the campaign, Gonzalez has touted his experience in state government as an asset for his candidacy. Massie, a long-time activist and the 1994 Democratic nominee for lieutenant governor, has pegged himself as the “outsider” candidate. “I think Jay wants to be a bold leader, but I don’t think he’s had the full imagination of all our opportunities,” said Massie, who referred to himself as a “movement leader.” Massie recently received the support of Our Revolution Massachusetts, a progressive group backed by Senator Bernie Sanders.

Gonzalez challenged Massie’s “movement leader” moniker saying, “I think a good indicator of the ability to be a movement leader is the strength of the campaign.”

In June, Gonzalez, who used to run a local health insurance company, earned the state’s Democratic Party endorsement with 70.4 percent of delegate support to Massie’s 29.6 percent. Whoever wins the September 4 primary will face either Baker or his Republican primary opponent, Scott Lively, in the general election on Nov. 6.

Correction: An earlier version of this story misidentified the group that has endorsed Robert Massie. The group's name is Our Revolution Massachusetts and has been corrected in the text of this article.