Campaigners hailed the move as a major step forward for LGBT+ rights.
The gay marriage law is likely to be put to a nationwide referendum next year before taking effect, at the request of the Christian, ultra-conservative Federal Democratic Union party.
What did lawmakers vote for?
The marriage bill has seen multiple rounds of debate since 2013. The approved wording of the bill allows gays and lesbians to marry. It will also allow lesbians to access sperm donations.
Under current legislation, same-sex couples can enter into "registered partnerships." This does not provide the same rights as marriage, including rights to obtain citizenship and the joint adoption of children.
Lawmakers also voted to simplify legal name and gender marker changes on identity documents. Trans and intersex people will now be able to do this by making a declaration at civil registry offices without the need for a court or a doctor. This is known as "self-ID," according to the advocacy group Transgender Europe.
Currently, both children and adults have to apply to a court to change their gender that can cost up to CHF1,000 (€924, $1,130).
The minimum age for legal changes to gender without parental consent was set at 16.
LGBT+ bill 'a milestone'
"This is not only a milestone in the fight for the rights of the Swiss LGBT population but also an important victory for their dignity, their acceptance and their inclusion in society," Marriage For All, a campaign group, said on its website.
"On the one hand, we're super happy there will be this legal gender recognition based on self-determination, in a very quick and simple procedure," said Alecs Recher, the head of legal services at Transgender Network Switzerland, an advocacy group.
However, Recher told Reuters news agency that the age limit was "a step back for those under 16."
Will there be a referendum?
Opponents now have 100 days to collect the 50,000 signatures needed to trigger a referendum on the same-sex marriage bill.
A survey commissioned by a gay advocacy group Pink Cross in February showed more than 80% of Swiss support same-sex marriage, suggesting the law would likely take effect.
kmm/sms (Reuters, AFP)