The administration of Democratic Governor Tom Wolf immediately appealed the ruling, which deemed the law unconstitutional. That puts its implementation on hold while the Pennsylvania Supreme Court weighs the matter.
Three Republican judges agreed with the GOP who had challenged the law, Act 77, saying the state's constitution required people to vote in person unless they had a specific excuse, such as having a disability or being away from home on Election Day. Two Democratic judges dissented.
Implemented in 2019 with Republican support, Act 77 had eliminated such requirements for mail-in ballots. Democrats actively used the method of voting in 2020, helping U.S. President Joe Biden win the state over Donald Trump by some 80,000 votes.
Commonwealth Court President Judge Mary Hannah Leavitt said that while she believed Pennsylvanians would support eliminating the in-person voting requirement, a constitutional amendment rather than legislation was the appropriate first step.
"An amendment to our Constitution that ends the requirement of in-person voting is the necessary prerequisite to the legislature's establishment of a no-excuse mail-in voting system," Leavitt wrote in the ruling.
The ruling comes ahead of important races in Pennsylvania, including the one to replace retiring Republican U.S. Senator Pat Toomey, a contest that could help determine control of Congress in November's midterm elections.
Josh Shapiro, the state's Democratic attorney general, said he was confident the Pennsylvania Supreme Court, which has a Democratic majority, would overturn the lower court's ruling.
"This opinion is based on twisted logic and faulty reasoning, and is wrong on the law," Shapiro, who is running for governor, said in a statement, predicting that there would not be any "immediate impact on Pennsylvania's upcoming elections."
Act 77 was the result of a deal struck between Republican and Democratic lawmakers that expanded access to mail-in ballots and eliminated straight-party voting, which allowed voters to select a party instead of a candidate in each race.
Republicans had long sought to ditch the party-line vote because it was seen as an advantage in a state where Democrats outnumber Republicans.
Some Democrats lament the tradeoff, particularly in light of Friday's ruling. They said it was to blame for big losses for the party's down-ballot candidates in 2020, even as Biden prevailed at the top of the ticket.
"It was a mistake and it crushed us," said Joe Foster, chairman of the Democratic Party in Montgomery County, the largest of the Philadelphia suburbs.
Republicans changed their views on the law after Trump lost the state, with many of them embracing the former president's false claims that widespread fraud tied to mail-in ballots was behind his defeat.
The COVID-19 pandemic also made mail-in voting more attractive to voters worried about health risks. More than 2.6 million Pennsylvanians voted by mail in the 2020 election. Roughly three-quarters of the ballots cast by mail selected Biden.
(reporting by Jarrett Renshaw in Philadelphia and Nathan Layne in Wilton, Connecticut; Editing by Richard Chang, David Gregorio and Mark Porter)
By Jarrett Renshaw and Nathan Layne