The ruling by the court in Ottawa brings to the final stages a long, bitter fight over whether gays and lesbians should be allowed to marry in Canada.
Judges in six provinces and one territory have already overturned the traditional definition, allowing thousands of same-sex weddings.
Thursday's Supreme Court ruling did not say whether same-sex marriage is required by the constitution.
However, it noted the federal government, by not fighting a number of lower court rulings, had accepted the position that barring gays from marriage is discriminatory.
Canada would join Belgium and the Netherlands in allowing gay marriage if the government acts to make it legal nationwide.
To pass in the House of Commons, the legislation needs the approval of about 44 of the 95 Liberal backbench members of Parliament to obtain a 155-vote majority.
One top Liberal predicted the legislation should pass easily after its introduction, likely early next year. It already has the support of the 38-member Liberal cabinet and virtually all the 54 Bloc Quebecois and 19 New Democrat MPs.