Chief U.S. District Judge Vaughn Walker made his ruling in a lawsuit filed by two gay couples who claimed the voter-approved ban violated their civil rights.
Gay couples waving rainbow and American flags outside the courthouse cheered, hugged and kissed as word of the ruling spread.
"This is a victory for the American people. It's a victory for our justice system," said former U.S. Solicitor General Theodore Olson, who delivered the closing argument at trial for opponents of the ban.
He said the ruling "vindicates the rights of a minority of our citizens to be treated with decency and respect and equality in our system."
California Gov. Arnold Schwarzenegger also praised the ruling as an important step toward equality and freedom for all people.
Despite the favorable ruling for same-sex couples, gay marriage will not be allowed to resume immediately. Judge Walker said he wants to decide whether his order should be suspended while the proponents of the ban pursue their appeal in the 9th U.S. Circuit Court of Appeals.
The judge ordered both sides to submit written arguments by Friday on the issue.
California voters passed the ban as Proposition 8 in November 2008, five months after the state Supreme Court legalized gay marriage.
Supporters argued the ban was necessary to safeguard the traditional understanding of marriage and to encourage responsible childbearing
Walker, however, found it violated the Constitution's due process and equal protection clauses while failing "to advance any rational basis in singling out gay men and lesbians for denial of a marriage license."
"Indeed, the evidence shows Proposition 8 does nothing more than enshrine in the California Constitution the notion that opposite-sex couples are superior to same-sex couples," the judge wrote in his 136-page ruling.
He also said proponents offered little evidence that they were motivated by anything other than animus toward gays — beginning with their campaign to pass the ban, which included claims of wanting to protect children from learning about same-sex marriage in school.
"Proposition 8 played on the a fear that exposure to homosexuality would turn children into homosexuals and that parents should dread having children who are not heterosexual," Walker wrote.
Both sides previously said an appeal was certain if Walker did not rule in their favor. The case would go first to the 9th U.S. Circuit Court of Appeals, then the Supreme Court if the high court justices agree to review it.
Walker heard 13 days of testimony and arguments since January during the first trial in federal court to examine if states can prohibit gays from getting married.
The plaintiffs presented 18 witnesses. Academic experts testified about topics ranging from the fitness of gay parents and religious views on homosexuality to the historical meaning of marriage and the political influence of the gay rights movement.
Olson teamed up with David Boies to argue the case, bringing together the two litigators best known for representing George W. Bush and Al Gore in the disputed 2000 election.
Defense lawyers called just two witnesses, claiming they did not need to present expert testimony because U.S. Supreme Court precedent was on their side. The attorneys also said gay marriage was an experiment with unknown social consequences that should be left to voters to accept or reject.
Former U.S. Justice Department lawyer Charles Cooper, who represented the religious and conservative groups that sponsored the ban, said cultures around the world, previous courts and Congress all accepted the "common sense belief that children do best when they are raised by their own mother and father."
In an unusual move, the original defendants, California Attorney General Jerry Brown and Schwarzenegger, refused to support Proposition 8 in court.
That left the work of defending the law to Protect Marriage, the group that successfully sponsored the ballot measure that passed with 52 percent of the vote after the most expensive political campaign on a social issue in U.S. history.
Currently, same-sex couples can only legally wed in Massachusetts, Iowa, Connecticut, Vermont, New Hampshire and Washington, D.C.
The ruling puts Walker at the forefront of the gay marriage debate and marks the latest in a long line of high-profile legal decisions for the longtime federal judge.
He was appointed by Ronald Reagan, but his nomination was held up for two years in part because of opposition from gay rights activists. As a lawyer, he helped the U.S. Olympic Committee sue a gay ex-Olympian who had created an athletic competition called the Gay Olympics.
Walker is a Republican. He said he joined the party while at Stanford University during the Vietnam War protests, and spent two years clerking for a judge appointed by Richard Nixon.