A U.S. federal judge has blocked a Mississippi law that would have allowed residents to refuse services to same-sex couples based on religious beliefs.

U.S. District Judge Carlton Reeves blocked the law late Thursday, just hours before it was meant to take effect Friday, saying it violates the constitution's equal protection guarantee.

State attorneys are expected to appeal the ruling.

The controversial law, which has left the southern state subject to boycotts and criticism, would protect three beliefs: that marriage is only between a man and a woman; that sex should only take place in such a marriage; and that a person's gender is determined at birth and cannot be changed.

Local businesses also would be able to deny service to lesbian, gay, bisexual and transgender customers based on religious beliefs.

Many musicians canceled shows in recent months in Mississippi and the nearby state of North Carolina, which recently passed a bill requiring transgender people to use the bathroom corresponding to their gender at birth.