The Supreme Court on Monday upheld Mississippi’s grace period for late-arriving mail-in ballots, rejecting a push by the Trump administration to invalidate a state law.

The ruling means Mississippi’s law, which allows elections officials to count ballots postmarked by Election Day and received up to five business days later, will remain in place, at least through the midterm elections.

In a 5-to-4 vote, Chief Justice John G. Roberts Jr. and Justice Amy Coney Barrett joined the court’s three liberals in supporting the state law. The majority found that nothing in federal statutes required ballots to be received by Election Day.

Although the decision focused on a challenge to Mississippi’s law, the ruling appeared to leave in place similar laws in at least 18 other states and territories, including 2026 battleground districts in Nevada and California, in a blow to Republican efforts to roll back mail-in balloting.

It is also a defeat for President Trump, who has long criticized voting by mail, falsely claiming that the practice is open to fraud and helped lead to his defeat in the 2020 presidential election.

On social media, Mr. Trump called the ruling a “tremendous loss.” He used the court’s decision to push Congress to pass his priority voting legislation, known as the SAVE America Act, saying it was “more important than ever” for lawmakers to act. The contentious measure would put in place restrictions on mail-in ballots and add new voter identification requirements.

The state law at issue was adopted by Mississippi’s Republican-led legislature during the pandemic. But the Republican National Committee and Mississippi’s state G.O.P. later challenged the measure in court, arguing that federal law sets out Election Day as the day that ballots should be considered final.

Writing for the majority, Justice Barrett described the court’s decision as a narrow one, focused solely on the question of whether states could enact laws providing grace periods for late-arriving ballots to be counted.

But she also more broadly explored the evolving history of voting practices in the country, and how states had come to adopt practices allowing people to vote by mail. She described early elections as “lively public events” that involved “picnics, drinking and boisterous celebration.” After the Civil War, she noted, some states allowed soldiers to vote from afar with absentee ballots. She wrote that during World War I, some states began the practice of counting absentee ballots received after Election Day.

Today, she wrote, the practice is widespread, citing examples of the kind of people whose ballots were at stake in Mississippi as “college students away from home, and senior citizens.”

Got a news tip about the courts? If you have information to share about the Supreme Court or other federal courts, please contact us.

“The defining element of an ‘election’ — the term used in all three federal statutes — has always been the electorate’s choice of candidate,” Justice Barrett wrote, adding that “the electorate’s choice is made when voting is complete, not when ballots are received.”

In dissent, Justice Samuel A. Alito Jr. wrote that “Election Day is a specified date, not a span of multiple days,” asserting that the majority had based its decision “on a flawed understanding of the Election Day statutes.”

Justice Alito was joined in full by two of the court’s other conservatives — Justices Clarence Thomas and Neil M. Gorsuch — and in part by Justice Brett M. Kavanaugh. Justice Alito wrote that Mississippi’s acceptance of late-arriving ballots “effectively postpones the date on which the electorate’s choice is made,” violating federal laws.

The case is one of several legal challenges related to elections and voting before the court this term.

The justices in January sided with a Republican congressman from Illinois, agreeing candidates like him had the right to challenge the state’s rules governing vote counting. That ruling most likely paved the way for additional lawsuits over various balloting rules.

In late April, the justices struck down Louisiana’s congressional district map as an unconstitutional racial gerrymander, a decision that weakened the key remaining section of the Voting Rights Act of 1965, a landmark civil rights law.

The decision in the case immediately set off a scramble among states in the South to redraw their maps ahead of the midterms, including in Alabama, where the justices agreed to allow a map that eliminated one of the state’s two majority-Black districts, citing their Louisiana ruling.

The court is also weighing a Republican challenge to limits on how much political parties can spend in coordination with candidates, a case on which the court is expected to rule on Tuesday.

Despite Mississippi’s victory, the fate of its mail-in ballot grace period may still hang in the balance.

After Monday’s decision, Gov. Tate Reeves, a Republican and staunch conservative, posted on social media that he planned to ask state lawmakers to repeal the mail-in ballot grace period, and to require ballots be received by 5 p.m. on Election Day during the next legislative session.

He added that “just because the court ruled the practice constitutional doesn’t mean we should allow it in our state.”

Emily Cochrane contributed reporting.