SALT LAKE CITY -- Episcopalians have voted to allow religious weddings for same-sex couples, just days after the U.S. Supreme Court legalized same-sex marriage nationwide.

The vote came Wednesday in Salt Lake City at the denomination's national assembly. The measure passed by an overwhelming margin in the House of Deputies, the voting body of clergy and lay people at the meeting. The day before, the House of Bishops had approved the resolution, 129-26 with five abstaining.

"Rapid changes in civil law concerning marriage in the United States, along with the responses received as part of the SCLM church-wide consultation process, indicate a need for equivalent proper liturgies in jurisdictions where same-sex marriage is legal," according to a statement on the church's website.

"Further, the SCLM consultation process indicated a pastoral need for equivalent marriage rites that could be used by any couple."

Get Breaking News Delivered to Your Inbox

Prior to the vote, the Very Rev. Brian Baker of Sacramento said the church rule change was the result of a nearly four-decade long conversation that has been difficult and painful for many. Baker, chair of the committee that crafted the changes, said church members have not always been kind to one another but that the dynamic has changed in recent decades.

"We have learned to not only care for, but care about one other," Baker said. "That mutual care was present in the conversations we had. Some people disagreed, some people disagreed deeply, but we prayed and we listened and we came up with compromises that we believe make room and leave no one behind."

Baker said the denomination's House of Bishops prayed and debated the issue for five hours earlier this week before passing it on to the House of Deputies.

The new rule eliminates gender-specific language from church laws on marriage so that same-sex couples could have religious weddings. Instead of "husband" and "wife," for example, the new church law will refer to "the couple." Under the new rules, clergy can decline to perform the ceremonies.

In 2003, the New York-based denomination made history by electing its first openly gay bishop. Since then, many Episcopal dioceses have allowed their priests to perform civil same-sex weddings. Still, the church hadn't changed its laws on marriage.

The Episcopal Church, with nearly 1.9 million members, has included many of the Founding Fathers and presidents.

Among mainline Protestant groups, only the United Church of Christ and the Presbyterian Church (U.S.A.), both of which are smaller than the Episcopal Church, allow same-sex weddings in all their congregations.

The 3.8-million-member Evangelical Lutheran Church in America lets its congregations decide for themselves, and many of them host gay weddings.

The United Methodist Church, by far the largest mainline Protestant church with 12.8 million members, bars gay marriage, although many of its clergy have been officiating at same-sex weddings recently in protest.

The Episcopal Church is the U.S. wing of the Anglican Communion, an 80 million-member global fellowship of churches. Ties among Anglicans have been strained since Episcopalians in 2003 elected Bishop Gene Robinson, who lived openly with his male partner, to lead the Diocese of New Hampshire.

On the eve of the U.S. vote, Archbishop of Canterbury Justin Welby, spiritual leader of the world's Anglicans, issued a statement expressing deep concern about the move to change the definition of marriage.

Robinson, now retired, said he is breathless about how quickly gay rights have gained acceptance since the days when he was getting death threats and forced to wear a bulletproof vest to his consecration 12 years ago.

"Conservative churches are hemorrhaging young people because young people today have gay, lesbian, bisexual and transgender friends," Robinson said. "In increasing numbers, they do not want to belong to a church that condemns their friends that they know to be wonderful people."

Faith groups across the spectrum of belief, from the Episcopal Church to the Southern Baptists, have been losing members as more Americans say they identify with no particular religion. The Episcopal Church has shrunk 18 percent over the last decade, after more than a generation of steady decline.

After the Supreme Court ruling last week, many conservative churches, including the Southern Baptists and the Mormons, renewed their opposition to gay marriage.

The Episcopal Church has already made history during the convention, electing its first black presiding bishop. Bishop Michael Curry of North Carolina won in a landslide over the weekend.

Curry has allowed same-sex church weddings in North Carolina, and he said the Supreme Court "affirmed the authenticity of love" by legalizing gay marriage.