BOSTON — The Massachusetts Senate passed a bill on Thursday that would legalize casino gambling, paving the way for three resort-style casinos and one slots parlor in the state.

Past attempts to legalize casino gambling failed, but the idea gained popularity recently as the recession tempered the state’s economic growth.

The Senate bill passed 24 to 14 after days of debate. Last month, the state’s House passed a bill allowing the same number of gambling establishments. Some differences remain, but they are expected to be resolved in a conference committee of the Democratic-controlled Legislature, and Gov. Deval Patrick has indicated he will sign the final legislation.

Last year, a gambling measure failed when Mr. Patrick and the House speaker, Robert A. DeLeo, disagreed on the number of slots parlors. The new legislation emerged after months of closed-door negotiations involving Mr. Patrick, Mr. DeLeo and Senate President Therese Murray.