The bill, which also legalises adoption by same-sex couples, was passed by 321 votes to 225 in the French parliament.
The decision follows a divisive public debate with some of the biggest protests seen in France in recent years.
Hundreds of opponents of the measure rallied outside the National Assembly building in central Paris as the result was announced.
Frigide Barjot, a comedian who uses her stage name, told her supporters: “We are going to show them that this is not over. I solemnly ask the president to hold a referendum on the subject.”
Inside the National Assembly chamber, two opponents tried to unfurl a banner before being ejected.
Thousands of police armed with water cannon were deployed near parliament to deal with any repeat of the violence seen on the fringes of previous demonstrations.
Although rallies opposing the change have been overwhelmingly peaceful, there have been some clashes, blamed on far-right elements.
Opinion polls suggest a small majority of French people favour gay marriage, but surveys indicate fewer support adoption by same-sex couples.
Socialist President Francois Hollande made the law his flagship social reform.
He is expected to add his signature to the bill once it has cleared any challenge in the constitutional council.
Opponents of the measure, including the opposition UMP party, will try to convince the council that marriage is a constitutional issue.
However, analysts say that the council is unlikely to block the new law.
‘Breeze of joy’
The first weddings could take place in June, according to Justice Minister Christiane Taubira.
“We believe that the first weddings will be beautiful and that they’ll bring a breeze of joy, and that those who are opposed to them today will surely be confounded when they are overcome with the happiness of the newlyweds and the families,” she told the National Assembly.
Some argue this is the most important social reform in France since the death penalty was banned in 1981, says the BBC‘s Christian Fraser in Paris.
France is now the 14th country to legalise gay marriage after New Zealand last week.
It is also the ninth country in Europe to allow same-sex marriage after legalisation in the traditionally liberal Netherlands and Scandinavia, but also in strongly Catholic Portugal and Spain. Legislation is also moving through the UK Parliament.
But the measure has aroused stronger than expected opposition in France – a country where the Catholic Church was thought to have lost much of its influence over the public.
In January, a protest in Paris against the bill attracted some 340,000 people according to police – one of the biggest public demonstrations in France in decades. Organisers put the figure at 800,000.
Since then both sides have held regular street protests.
The opponents, backed by the Catholic Church and conservative opposition, say France already has civil partnerships for homosexual couples, and extending rights to marriage undermines an essential building block of society.