The Cannabis Act passed its final hurdle on Tuesday in a 52-29 vote in the Senate. The bill controls and regulates how the drug can be grown, distributed, and sold.
Canadians will be able to buy and consume cannabis legally as early as this September.
The country is the second worldwide to legalise the drug's recreational use.
Uruguay became the first country to legalise the sale of cannabis for recreational use in December 2013, while a number of US states have also voted to permit it.
Cannabis possession first became a crime in Canada in 1923 but medical use has been legal since 2001.
The bill will likely receive Royal Assent this week, and the government will then choose an official date when the law will come into force.
Prime Minister Justin Trudeau tweeted that until now, "it's been too easy for our kids to get marijuana - and for criminals to reap the profits".
But some groups objected to the new law, with opposition Conservative politicians and indigenous groups among those voicing concerns.
The government is expected to give the provinces and territories, as well as municipalities, eight to 12 weeks to set up the new marijuana marketplace.
This timeframe will also allow industry and police forces to prepare for the new legal framework.
In 2015, Canadians were estimated to have spent about C$6bn ($4.5bn, £3.4bn) on cannabis - almost as much as they did on wine.
It is likely that by mid-September, Canadians will be able to buy cannabis and cannabis oil grown by licensed producers at various retail locations.
Canadians across the country will also be able to order the drug online from federally licensed producers, and grow up to four plants at home.
Adults will be able to possess up to 30 grams (one ounce) of dried cannabis in public.
Edibles, or cannabis-infused foods, will not be immediately available for purchase but will be within a year of the bill coming into force. The delay is meant to give the government time to set out regulations specific to those products.
The minimum legal age to buy and consume marijuana has been set federally at 18, but some provinces have chosen to set it at 19.
Provinces are in charge of how it is sold and have the power to set various other limits on its use within their jurisdiction - like where it can be smoked.
It will be illegal to possess over 30 grams of cannabis, grow more than four plants per household, and to buy from an unlicensed dealer.
Penalties will be severe. Someone caught selling the drug to a minor could be jailed for up to 14 years.
Some critics say the penalties are too harsh and not proportional to similar laws like those around selling alcohol to minors.
Cannabis is banned in most countries but a number of places have decriminalised its use in recent years. The UK government said recently it would review the use of medicinal cannabis.
It is legal for medicinal purposes in 14 European countries, Israel, Argentina, Puerto Rico, Panama, Mexico, Turkey, Zambia and Zimbabwe.
In the US, medicinal use is allowed in 29 states and the District of Columbia - nine states of which have legalised both medical and personal cannabis use.
Spain, the Netherlands, Portugal, Slovenia, Jamaica, Chile, Peru, Colombia, Ecuador, Luxembourg and some parts of India are among those that have decriminalised the drug for personal use.
Conservative Party leader Andrew Scheer said he was apprehensive it would normalise cannabis use and make it more accessible.
Leo Housakos, a Conservative senator from Quebec, tweeted to say that he thought the law would be "catastrophic for Canadian generations to come".
One specific concern being raised is the legal minimum age being set at 18 instead of 25, as was recommended by the government's own task force. Opponents also question the potential public health impact of legalisation.
Meanwhile, indigenous groups and politicians have voiced fears that their communities were not adequately consulted in the run-up to the vote.
Indigenous services minister Jane Philpott and health minister Ginette Petitpas Taylor had to write a letter to the chair and deputy chair of the Senate's Committee on Aboriginal Peoples earlier in June promising a full report to parliament addressing their concerns, narrowly averting a delay to the law's passage.
This legislation fulfils a 2015 campaign promise by Mr Trudeau, the leader of the Liberal Party.
The prime minister has argued that Canada's nearly century-old laws criminalising use of the drug have been ineffective, given that Canadians are still among the world's heaviest users.
Polls have repeatedly indicated that a solid majority of Canadians are supportive of the move.
The decision to legalise recreational use of marijuana in Canada comes as global trends shift away from criminal prohibition of the widely used drug.