Tuesday’s mayoral debate underscored the central challenge to state Representative Martin J. Walsh’s candidacy, even as he has racked up a formidable string of endorsements: staving off the perception that he is too shackled to organized labor to manage the city’s finances prudently.

Time and again in the opening rounds of his second debate with Councilor at Large John R. Connolly, Walsh was wedged into a defensive crouch over his lifelong ties to the labor movement, both in his work in the Legislature and as a professional advocate for building trades unions.

While even Connolly advocates agree that Walsh has established momentum with two weeks remaining until the Nov. 5 election, Connolly made clear where he will try to hamstring Walsh.

When comoderator Margery Eagan asked Walsh about fliers mailed by labor groups attacking Connolly, the Dorchester Democrat denounced the literature and negative campaigning generally, but was left open to guilt by association.

“Marty has premised his campaign on the notion that, because he’s a labor leader, he’s going to be able to get labor leaders to do things they wouldn’t normally do,” Connolly said.

Walsh responded that his record working to change public employee pensions and health insurance in the Legislature should serve as reassurance that he would effectively broker compromises with unions. But Connolly shot back, “It seems like they can’t wait to get you at the table.”

Even a question aimed at Connolly’s council vote in favor of a $24 million tax break for the insurance giant Liberty Mutual, which cut benefits for workers while paying its chief executive nearly $50 million annually, allowed Connolly to deftly transition into a discussion of Walsh’s labor advocacy. Connolly pointed out that Walsh, as head of the Building and Construction Trades Council of the Metropolitan District, had urged approval of the tax break, to help retain the company’s business in the city.

It was a lost opportunity for Walsh to highlight his campaign’s more populist appeal.

Part of that appeal is rooted in his upbringing as the son of Irish immigrants, offering an easy contrast with Connolly, who is part of a well-connected political family.

Walsh went to college at night as an adult, while Connolly worked at Ropes & Gray and then helped run his own law firm.

The city’s political history will probably not record that the eventual victor, whoever it may be, soared to the mayoralty on the strength of his debating chops. Connolly, too, encountered turbulence.

He struggled in trying to distance himself from tenant evictions handled by his law firm and to answer why his campaign has spent so much time playing up his three years as a teacher, while minimizing his work as a lawyer.

Their differing biographies and résumes have helped create an undeniable class dynamic in the race, one that Walsh has balked at exploiting. Even in what was perhaps his stiffest broadside of the night, requesting that Connolly more fully disclose the details of his legal work, Walsh was polite, perhaps to a fault.

“I would like to ask John if he would open up his law practice for the last 12 years,” he said.

Walsh’s union ties are not in and of themselves a detriment; indeed, he has derived strong support from labor and used those relationships on Beacon Hill as a liaison to legislative leaders in brokering some of the key reform compromises of the last several years.

But each time the discussion veers onto that turf, it is an invitation for questions about Walsh’s independence, and a missed chance for Walsh to trumpet his life story and work in human services.

Walsh was stronger Tuesday night in discussing the heavy backing he has received from other elected officials, particularly those of color, which his campaign has gleefully trumpeted and which appear to have rattled Connolly’s camp.

With both candidates turning in fairly weak performances in communities of color during the preliminary election, such support could prove pivotal in November.

Walsh picked up endorsements from three rivals from the preliminary — Charlotte Golar Richie, Felix G. Arroyo, and John F. Barros — followed by state Senator Linda Dorcena Forry, then state Representatives Carlos Henriquez, Russell Holmes, Gloria Fox, state Senator Sonia Chang Diaz, and Councilor Tito Jackson, representing a resounding blast of approval from the city’s minority political establishment. On Monday, US Representative Michael E. Capuano announced he too would work for a Walsh victory.

“If you look at the endorsements I’ve received, they’re from all corners of the city,” Walsh said Tuesday.

But, for Walsh to make them count, he’ll need to move more skillfully to capitalize on opportunities like those he missed on Tuesday.