Finding Pennsylvania's 1996 Defense of Marriage Act unconstitutional, District Court Judge John Jones III wrote: "By virtue of this ruling, same-sex couples who seek to marry in Pennsylvania may do so, and already married same-sex couples will be recognized as such in the Commonwealth."
The ruling makes Pennsylvania the 19th U.S. state where gay marriage is allowed, a movement that has gained momentum since the Supreme Court ruled last June that legally married same-sex couples are eligible for federal benefits.
Most recent court rulings allowing gay marriage have included a stay pending appeal, but Jones' ruling does not.
There is, however, a mandatory three-day waiting period for all weddings in Pennsylvania.
In the ruling, the judge noted that the issue of gay marriage "is a divisive one."
"Some of our citizens are made deeply uncomfortable by the notion of same-sex marriage," he wrote. "However, that same sex marriage causes discomfort in some does not make its prohibition constitutional. Nor can past tradition trump the bedrock constitutional guarantees of due process and equal protection."
He compared Pennsylvania's ban on same-sex marriage to the school segregation laws overturned by the U.S. Supreme Court's 1954 landmark Brown vs. Board of Education decision.
"We are a better people than what these laws represent, and it is time to discard them into the ash heap of history," he wrote.
The legal challenge to Pennsylvania's Defense of Marriage Law was filed last July by several gay couples.
Challengers argued that under the ban, gay couples are denied an inheritance tax exemption for surviving spouses and survivor benefits to partners of police officers killed in the line of duty.
Pennsylvania Attorney General Kathleen Kane announced two days after the lawsuit was filed that she would not defend the case, which led to calls for impeachment from conservative legislators, an effort that is ongoing.
Governor Tom Corbett appointed William Lamb, a Republican former prosecutor, to handle the appeal.