Canada has followed Belgium, the Netherlands and Spain in legalising gay marriages.
The Senate, dominated by the ruling Liberal party, overwhelmingly approved the bill.
The government said it had to draw up legislation after courts in eight of the 10 provinces ruled that a heterosexual-only definition of marriage was unconstitutional.
Hundreds of foreigners have travelled to Canada to get married since some provinces made gay unions legal in 2003.
Justice minister Irwin Cotler said on Wednesday: “I would say Canada is a leader, and I think 10 years from now when we’ll look back at this, we’ll say: You know, they did the right thing, maybe a little bit ahead of their time.”
Canada’s lower house of parliament had already approved the bill despite fierce opposition from conservative politicians and from religious groups.
While the legislation grants gay couples the right to full civil marriages, it makes clear that religious officials will not be obliged to marry them.