Shelby said the state failed to show that allowing same-sex marriages would affect opposite-sex marriages in any way.
"In the absence of such evidence, the State's unsupported fears and speculations are insufficient to justify the State's refusal to dignify the family relationships of its gay and lesbian citizens," Shelby wrote.
It was unclear what the immediate effect would be, because the state can still appeal. The Utah attorney general's office said it would issue a statement on the ruling later.
The ruling comes the same week New Mexico's highest court legalized gay marriage after declaring it unconstitutional to deny marriage licenses to same-sex couples. A new law passed in Hawaii last month now allows gay couples to marry there.
The ruling is the first on a state same-sex marriage ban since the Supreme Court last summer struck down part of the Defense of Marriage Act, which stipulated that marriage was between a man and woman.
During a nearly four-hour hearing earlier this month in Salt Lake City, attorneys for the state argued that Utah's law promotes the state's interest in "responsible procreation" and the "optimal mode of child-rearing." They also asserted it's not the courts' role to determine how a state defines marriage, and that the Supreme Court ruling doesn't give same-sex couples the universal right to marry.
The lawsuit was brought by three gay and lesbian couples in Utah. One of the couples was legally married in Iowa and just wants that license recognized in Utah.
Many similar court challenges are pending in other states, but Utah's has been closely watched because of the state's history of staunch opposition to gay marriage as the home of The Church of Jesus Christ of Latter-day Saints.
Peggy Tomsic, the attorney who represents the three couples, applauded Shelby's courage in making the ruling.
"We cannot capture in words the gratitude and joy plaintiffs feel," Tomsic said in a statement.
But she warned that the legal fight is not over, saying she expects the state to appeal the decision to the 10th U.S. Circuit Court of Appeals.
During this month's hearing, Tomsic contended marriage is a fundamental right protected by the U.S. Constitution. She said the case embodies the civil rights movement of our time, saying discrimination has gone on long enough.
She said Utah's law, which passed with two-thirds of the vote, is "based on prejudice and bias that is religiously grounded in this state."