Unions fought hard to stop the bill, launching a radio ad that assailed the plan and warning legislators that if they voted for the measure, they could lose their union backing in the next election. After the vote, labor leaders accused House Speaker Robert A. DeLeo and other Democrats of turning their backs on public employees.

“It’s pretty stunning,’’ said Robert J. Haynes, president of the Massachusetts AFL-CIO. “These are the same Democrats that all these labor unions elected. The same Democrats who we contributed to in their campaigns. The same Democrats who tell us over and over again that they’re with us, that they believe in collective bargaining, that they believe in unions. . . . It’s a done deal for our relationship with the people inside that chamber.’’