Employers who have religious objections to contraception can refuse to pay for birth control, the U.S. Supreme Court ruled Monday in a 5-4 decision.

The ruling in Burwell v. Hobby Lobby Stores Inc. and Conestoga Wood v. Burwell was a blow to the Obamacare provision that required contraception to be covered by for-profit companies’ health insurance plans. The Obama administration now has to come up with another way of providing free contraception to women who are covered by those companies’ health plans, according to the Associated Press.

“The court says that the government has failed to show that the mandate is the least restrictive means of advancing its interest in guaranteeing cost-free access to birth control,” SCOTUSblog’s Amy Howe wrote while live blogging the opinion.

The ruling comes with some caveats. It applies only to companies controlled by a few people where there's virtually no difference between the business and the owners, according to the AP. It also applies only to contraception and not blood transfusions or vaccinations.

Oklahoma City-based Hobby Lobby, which has more than 15,000 full-time employees in more than 600 crafts stores in 41 states, is owned by the Green family, who are evangelical Christians. Conestoga Wood Specialties Corp., of East Earl, Pennsylvania, is owned by a Mennonite family and employs 950 people in making wood cabinets. The two companies challenged the contraception mandate on the grounds that it violates their religious freedom by requiring them to pay for methods of contraception they find morally objectionable.

Supreme Court Justice Samuel Alito wrote the majority opinion of the court, while three justices wrote dissenting opinions, including Justice Ruth Bader Ginsburg, who said the ruling was a “decision of startling breadth.” Justices Stephen Breyer and Elena Kagan also wrote dissenting opinions.

Ginsburg, Breyer and Kagan were joined by Justice Sonia Sotomayor in the minority.

Correction: A previous version of this story misspelled Burwell. We regret the error.