DENVER — Colorado lawmakers passed legislation on Tuesday to legalize civil unions for same-sex couples, following several years of bitter debate over the issue.

Pushed by the Democrat-led legislature and backed by a handful of Republicans, the bill had been widely expected to gain approval this year, after Democrats retook control of the State House of Representatives last November.

But Tuesday’s victory was no less meaningful for supporters who had come frustratingly close to passing the legislation in 2012. And it signaled the latest shift in a state that was once seen as hostile toward gays and lesbians.

“This is a historic moment to be seized and to be cherished,” said Representative Pete Lee, a Democrat from Colorado Springs, as the House weighed civil unions for the final time on Tuesday.