The supervised injection site opened in Vancouver in 2003 with a federal exemption permitting illegal drug use.
Its supporters say it has helped prevent overdoses, reduced infections, and curbed crime and open drug use.
But the federal government said in 2008 that the facility should close, arguing it promoted addiction.
The top court issued its unanimous 9-0 decision on Friday.
Addicts must bring their own drugs to the Insite facility, where they are supplied with clean needles and sterilised water. They inject at 12 stainless-steel alcoves with mirrors on the walls so nurses on a raised platform can see them.
The court said in its ruling that in the clinic's eight-year history, "Insite has been proven to save lives with no discernible negative impact on the public safety and health objectives of Canada".
"The risk of death and disease to injection drug users is grossly disproportionate to any benefit that Canada might derive from presenting a uniform stance on the possession of narcotics."
Correspondents say the ruling suggests the right of a province to provide healthcare supersedes the federal government's right to enforce drug laws.
It is thought that the Supreme Court's decision could pave the way for similar facilities to open in other parts of Canada.
The ruling was welcomed by users of the facility and healthcare professionals alike. A crowd celebrated on the street outside Insite.
"Addiction-related drug use is a health issue and not a criminal justice issue," Debra Lynkowski, chief executive of the Canadian Public Health Association, told reporters.
"Collectively, we have the responsibility to protect the health of all Canadians, no matter what their situation."
But Health Minister Leona Aglukkaq was disappointed with the decision.
She told the Canadian parliament: "Our government believes that spending more money on treatment and to help people get off drugs is the best investment we can make."
She added that the government would be reviewing the court's decision.
The facility has been operating under the constitutional exemption to Canada's Controlled Drugs and Substances Act.
But the federal government refused to renew the exemption in 2008, arguing that "harm-reduction" programmes diverted funding from addiction-treatment programmes.
The Supreme Court's ruling supports a decision made in 2008 by the Supreme Court of British Columbia.
As of 2009, there were 65 injection facilities in 27 cities in Canada, Australia and western Europe, according to the Canadian Medical Association Journal.

The 20-year-old spent the latter half of 2015-16 on loan with the Bantams.
He made four Europa League appearances and one Premier League appearance for the Hammers in 2015, before playing against Juventus in Sunday's friendly.
"I am excited to try to push this club on again," he told Bradford's club website. "The fans, players and staff were all brilliant first time around."
Find all the latest football transfers on our dedicated page.

The pair, who were wearing stage make-up, fake blood and white contact lenses, were returning from filming online sitcom Dead Town on Sunday.
Steve Lowe and Diane Holden of Ashton-under-Lyne were on the M62 near Warrington when they were pulled over.
Police shared a picture and tweeted "posing as Zombies - takes all sorts".
The pair were filming the third and final episode of Dead Town which is based in Runcorn, Cheshire when the North West Motorway Police officer pulled them over in an unmarked car.
Mr Lowe said the officer burst out laughing when he saw their attire.
"I think he was very surprised; he wasn't frightened but pleasantly amused.
"He asked if he could take a photograph because no-one would believe him back at the station."
Mr Lowe, 60, said he has been dressing up as a zombie for a couple of years.
"It is brilliant; really good fun. There is a big zombie community - it's a nice big zombie family."
A spokesman for Greater Manchester Police added: "No further action was taken."
North America's only legal drug-injection site can stay open, Canada's Supreme Court rules, in a defeat for the country's conservative government.
[NEXT_CONCEPT]
League One club Bradford City have re-signed West Ham United midfielder Josh Cullen on loan until January.
[NEXT_CONCEPT]
A couple dressed as zombies were stopped by concerned motorway police responding to reports of a woman being assaulted in a car.