A clear majority of German MPs have voted to legalise same-sex marriage, days after Chancellor Angela Merkel dropped her opposition to a vote.
The reform grants couples now limited to civil unions full marital rights, and allows them to adopt children.
Mrs Merkel's political opponents were strongly in favour. But the chancellor, who signalled her backing for a free vote only on Monday, voted against.
The bill was backed by 393 lawmakers, 226 voted against and four abstained.
The German legal code will now read: "Marriage is entered into for life by two people of different or the same sex", AFP news agency reported.
Following Friday's vote, Mrs Merkel said that for her marriage was between a man and a woman. But she said she hoped the passing of the bill would lead to more "social cohesion and peace".
How did this sudden vote come about?
During her 2013 election campaign, Mrs Merkel argued against gay marriage on the grounds of "children's welfare," and admitted that she had a "hard time" with the issue.
But in an on-stage interview with the women's magazine Brigitte on 26 June, she shocked the German media by saying, in response to an audience member's question, that she had noted other parties' support for gay marriage, and would allow a free vote at an unspecified time in the future.
The usually-cautious chancellor said she had had a "life-changing experience" in her home constituency, where she had dinner with a lesbian couple who cared for eight foster children together.
As the news spread on Twitter, supporters rallied under the hashtag #EheFuerAlle (MarriageForAll) - and started calling for a vote as soon as possible.
"It's time, Mrs Merkel" Green party leader Katrin Goering-Eckhart said then. "The Merkel faction cannot just sit out the debate on marriage for everyone."
Merkel, the canny operator? Jenny Hill, BBC News, Berlin
Angela Merkel voted against legalising same sex marriage. Nevertheless, she'll go down in history as the chancellor who made it possible. Friday marks a historic victory for the political left who've fought for years to bring the bill before parliament.
The bill is one of the very last measures to come through parliament before the September general election. By voting against it, Mrs Merkel has appealed to the more conservative members of her electorate. But, by allowing it to happen, she's cemented her growing reputation as a defender of liberal values and, perhaps more importantly, seen off an issue which might have come to haunt her later on.
If Mrs Merkel wins a majority in September, she's likely to seek coalition with parties who'd already indicated that same sex marriage legislation would have been a condition of partnership.
Why is this happening now?
Because of an upcoming general election. Germans go to the polls on 24 September, and continued opposition to a vote made Mrs Merkel risk looking anachronistic.
Mrs Merkel's coalition partners, the SPD, had ruled out a future coalition deal unless reform was agreed on. The Greens, the far-left Linke, and the pro-business Free Democrats took the same view.
The right-wing Alternative for Germany (AfD) is now the only party to oppose same-sex marriage.
But conservatives within Mrs Merkel's own CDU were against a change - as was the CDU's Bavarian sister party, the Christian Social Union (CSU), whose votes Mrs Merkel needs in the September election.
Commentators say this partly explains why she has rejected a vote on marriage equality until now - and why she was taken off-guard by the snap vote.
Where else in Europe has same-sex marriage?
A host of European countries have beaten Germany to a same-sex marriage law.
Civil marriages are legally recognised in Norway, Sweden, Denmark (excluding the Faroe Islands), Finland, Iceland, the Netherlands, Belgium, Spain, Portugal, Luxembourg, France, the UK (except Northern Ireland and Jersey), and the Republic of Ireland.
But in Austria and Italy - as in Germany before Friday's vote- gay couples are restricted to civil partnerships.