The Colorado Supreme Court ruled Monday that employers lawfully can fire workers for using marijuana when they’re not on the job, even though the drug is legal in the state, upholding two lower court decisions on the issue.

The case, which involved a quadriplegic man who lost his job at Dish Network LLC after testing positive for marijuana in violation of company policy, had been closely watched around the country—especially in states where medical marijuana use is legal.

Brandon Coats, who has a state-issued medical marijuana license, said that he used the drug only when he wasn’t working to help with his disabilities. In a 2011 lawsuit, he argued that Dish violated Colorado law by firing him for engaging in a “lawful” activity while not on the job.

But in its unanimous 6-0 decision, the state Supreme Court sided with Dish Network, which argued that marijuana remains illegal under federal law and employers should be allowed to maintain a drug-free workplace. The court said the company didn’t violate Colorado’s lawful activities statute when it fired Mr. Coats.

“The term ‘lawful’ refers only to those activities that are lawful under both state and federal law,” the decision said. “Therefore, employees who engage in an activity such as medical marijuana use that is permitted by state law but unlawful under federal law are not protected by the statute.”