DENVER – Colorado lawmakers took a historic vote to approve civil unions for gay couples Tuesday, delivering on a campaign promise from Democrats who have capitalized on the changing political landscape of a state where voters banned same-sex marriage not long ago.

The bill on its way to the desk of Democratic Gov. John Hickenlooper is expected to be signed into law within two weeks, capping a three-year fight over a proposal to grant gay couples rights similar to marriage.

Applause erupted in the Capitol as the bill won final passage on a 39-26 House vote, with two Republicans joining all Democrats to approve the measure. Several dozen people watching from the House gallery left smiling and hugging, and some wiped away tears of joy.

Once the measure is signed, Colorado will join eight states that have civil unions or similar laws. Nine states and the District of Columbia allow gay marriage.

“This is the best step toward equality Colorado could take right now. I’m thankful we got it done,” said Katy Jensen, a 34-year-old Denver engineer who plans a civil union with her partner after the bill becomes law on May 1.

Last year, Democratic Sen. Jessie Ulibarri, a gay lawmaker serving his first term, was among those in the House gallery with his children, watching as Republicans used their one-vote majority in the House to prevent the measure from being debated in the waning hours of the session, thus killing the bill.

“I sat with my kids at midnight, wondering what was going to happen the next time we had a tragedy.

“What would happen if I had to take my kids to the ER and then I was questioned whether or not I was really their dad,” said Ulibarri, one of eight gay Democratic lawmakers serving in the Colorado Legislature.

Civil unions for gay couples became a rallying cry for Democrats who took control of the Colorado House in last year’s elections, and they vowed an early vote on the proposal.

“Elections have consequences,” said Republican Rep. Frank McNulty, the former House speaker.

Democrats now control both chambers of the Legislature, and the party elected Colorado’s first gay House speaker, Mark Ferrandino.

“The people spoke in November, and we are fulfilling a promise we made at the end of last session,” Ferrandino said Tuesday.

The vote marks a dramatic political shift in Colorado, a western state with deep conservative roots that has become more moderate over the past decade.

In 1992, Colorado voters approved a ban on municipal antidiscrimination laws to protect gays.