The law will come into force on May 1st.
“Parliament on Wednesday adopted the bill on a gender-neutral marriage law,” parliament said in a statement.
Of 349 members of parliament, 261 voted in favour, 22 were opposed to the proposal, 16 abstained and 50 were absent.
In Sweden, heterosexuals can choose to marry in either a civil or religious ceremony, whereas homosexuals have until now only been allowed to register their “partnerships” in a civil ceremony.
Civil unions granting gays and lesbians the same legal status as married couples have been allowed under Swedish law since 1995.
Sweden, already a pioneer in giving same-sex couples the right to adopt children, would become one of the first countries in the world to allow gays to marry in a major Church.
The Lutheran Church, which was the state Church until 2000, has offered gays a religious blessing of their union since January 2007.
The Church, which counted 74 percent of Swedes as members in 2007, said on Wednesday it supported the new law.
While gay couples will be legally entitled to wed in church on May 1st, the Lutheran Church synod will decide in October whether or not to perform same-sex marriages.
Even if it decides to allow gay weddings, individual pastors could still refuse to perform such a service, although the Church would be legally obliged to provide a minister to supervise the ceremony.
The Swedish Association for Sexuality Education said Wednesday that option gave “authorities a legal right to discriminate”, and suggested that all religious communities’ right to perform marriage ceremonies be withdrawn.
Six of Sweden’s seven political parties were in favour of the law.
But the four-party centre-right government has been split on the issue, with the junior partner Christian Democrats opposed to the use of the word “marriage” for homosexual unions.