Almost two-thirds of Swiss voters have backed same-sex marriage in a referendum.
Some 64% supported the measure, making it one of the last countries in western Europe to legalise same-sex marriage.
Campaigners have hailed the vote as a historic moment for LGBT rights in the country.
In the build up to the vote, church groups and conservative political parties opposed the idea, saying it would undermine the traditional family.
Switzerland has allowed same-sex couples to register partnerships since 2007, but some rights are restricted.
The measure will make it possible for same-sex couples to adopt unrelated children and for married lesbian couples to have children through sperm donation.
It makes Switzerland the 30th country in the world to adopt same-sex marriage.
"It is a historic day for Switzerland, a historic day when it comes to equality for same-sex couples, and it is also an important day for the whole LGBT community," Jan Muller, of the "yes" campaign committee, told AFP news agency.
Justice Minister Karin Keller-Sutter said the first same-sex marriages would take place in July next year.
"Whoever loves each other and wants to get married will be able to do so, regardless of whether it is two men, two women, or a man and a woman," she said.
But Monika Rueegger, a politician with the right-wing Swiss People's Party and an opponent of the measure, said children and fathers were the losers.
"This was not about love and feelings," she told Reuters. "It was about children's welfare."
Over the last 20 years, most countries in western Europe have recognised same-sex marriage. However, in Switzerland many big decisions go to a nationwide ballot, and this can slow down major changes to social legislation.
The new law, which had the backing of the Swiss government and all major political parties except the People's Party, was passed by parliament in December.
However, it was then challenged by opponents, who gathered enough signatures to force a referendum.