HARRISBURG, Pa. (AP) — A wide expansion of mail-in voting in Pennsylvania survived a legal challenge on Tuesday before the state Supreme Court in a case brought by some of the same Republican state representatives who voted for the legislation nearly three years ago.

Millions of state voters have chosen to cast ballots by mail in recent elections, although Democrats have used it in far greater numbers and the law fell out of favor with Republicans as former President Donald Trump attacked it during his losing 2020 reelection campaign.

The 5-2 ruling, with the two Republican justices both voting no, means expanded vote-by-mail will almost certainly be in place for marquee races in November for governor and U.S. Senate.

“We find no restriction in our Constitution on the General Assembly’s ability to create universal mail-in voting,” wrote Justice Christine Donohue in the majority opinion.

Widener Law Commonwealth professor Michael Dimino, who argued the case, declined immediate comment.

A lower court panel with a majority of Republican judges had thrown out the law in January, a ruling put on hold while the state Supreme Court reviewed an appeal by the administration of Democratic Gov. Tom Wolf.

In the new decision, the justices agreed with Wolf’s argument that the lower court wrongly based its decision on court rulings that addressed older versions of the state constitution that had invalidated laws passed in 1839 and 1923 to expand absentee voting.

The majority cited a provision of the Pennsylvania Constitution, “method of elections,” that says all elections shall be by ballot “or by such other method as may be prescribed by law.”

Wolf’s lawyers had told the court the current version of the state constitution should not be interpreted to outlaw voting by mail that goes beyond allowing it for people who are out of town on business, ill, physically disabled or performing election day duties or a religious observance.

They said the constitution establishes only minimums for absentee and mail-in ballots, minimums that for decades have been expanded by letting military spouses and those on vacation to vote by absentee ballot even though neither is expressly permitted in the state constitution.

Wolf issued the following statement after the court’s ruling:

Today’s court ruling definitively asserts that mail-in voting is a legal and constitutional method for Pennsylvania voters. By upholding the law, which the General Assembly approved in 2019 in a bipartisan manner, this ruling assures that mail-in voting remains in place and Pennsylvanians will be able to cast their ballot legally in person or by mail without any disruption or confusion.

“Voting is a fundamental right — a right that we should ensure is accessible for all voters. Mail-in voting is a safe, secure and legal option for Pennsylvania voters to exercise that right. I will continue to advocate for voting reforms that remove barriers and increase access to voting.”

Gov. Tom Wolf

Meanwhile, 14 Republican state lawmakers sued last month in another attempt to get the mail-in voting law thrown out. That lawsuit hinges on a provision that says the law becomes void when any of its requirements are struck down in court.

The pending lawsuit says the “non-severability” provision was triggered by a May 20 decision by a panel of the 3rd U.S. Circuit Court of Appeals over the law’s requirement that mail-in ballots have a voter’s handwritten date on the outside envelope. The federal appeals court panel found that a handwritten date had no bearing on a voter’s eligibility in a Lehigh County judicial race last November.

More than half of states now allow no-excuse absentee voting. Pennsylvania joined them in 2019, when Wolf agreed to a deal that also got rid of the straight-ticket voting by party option on ballots. But many Republicans soured on the law as Trump began making baseless claims mail-in voting was rife with fraud and urged Republicans to avoid it.

Republican lawmakers have sought to restrict mail-in voting by expanding the photo ID requirements and banning drop boxes.

The GOP’s nominee for governor, state Sen. Doug Mastriano of Franklin County, voted for the law but now wants to repeal it.

In one post-election lawsuit in 2020, Republicans sought to invalidate the mail-in voting law and throw out all ballots cast under it in a bid to overturn Democrat Joe Biden’s victory in Pennsylvania. The state Supreme Court threw it out, saying the plaintiffs “failed to act with due diligence” in waiting to challenge the law until after Trump lost the election. The U.S. Supreme Court refused appeals to intervene.