The Supreme Court ruled unanimously Monday that a state may require presidential electors to support the winner of its popular vote and may punish or replace those who don’t, settling a disputed issue in advance of this fall’s election.

Justice Elena Kagan wrote for the court as it considered for the first time the issue of “faithless electors” and whether the Constitution sees members of the electoral college — whose votes ultimately elect the president — as representatives of the intent of their state’s voters or as independent thinkers.

The Washington state law at issue “reflects a tradition more than two centuries old,” Kagan wrote. “In that practice, electors are not free agents; they are to vote for the candidate whom the State’s voters have chosen.”

In an opinion that referred to both the Broadway musical “Hamilton” and the HBO sitcom “Veep,” Kagan added: “The State instructs its electors that they have no ground for reversing the vote of millions of its citizens. That direction accords with the Constitution — as well as with the trust of a Nation that here, We the People rule.”

With criticism flying about the electoral college, here's what you need to know about our system for electing the president. (Jenny Starrs/The Washington Post)

Lower courts had split on the issue, with one saying the Constitution envisions the electors as free to vote their consciences without fear of punishment or removal.

It was one of the rare political cases at the court that seemed not to favor one political party over another, which might explain the unanimity. (Justice Clarence Thomas disagreed with the majority’s reasoning but not the outcome).

Red and blue states alike urged the justices to settle the matter in advance of the “white hot” glare of November’s election. They said they feared that a handful of independent-minded members of the electoral college would decide the next president.

The court’s decision doesn’t eliminate that possibility completely. Not all states explicitly require conformity, and the opinion does not force them to set up such systems. Not all scenarios are covered. After she mentioned that the most rogue electoral votes were cast in 1872, when one of the candidates died after Election Day, Kagan wrote: “Because the situation is not before us, nothing in this opinion should be taken to permit the States to bind electors to a deceased candidate.”

Also not before the court was an initiative by some states to pledge their electors to the winner of the national popular vote, rather than their own statewide totals.

The court considered cases from the states of Washington and Colorado. Washington moved to fine Peter Bret Chiafalo and two others $1,000 after they voted for former secretary of state Colin Powell when the electoral college convened after the 2016 election. They had pledged to vote for Hillary Clinton, who won the state’s popular vote.

Colorado replaced Micheal Baca after he said he intended to vote for Ohio’s then-governor John Kasich (R) instead of Clinton, who won his state. Baca was part of a movement to try to deny Donald Trump the presidency.

As the court’s opinion noted of the 2016 contest: “Only seven electors across the Nation cast faithless votes — the most in a century, but well short of the goal. Candidate Trump became President Trump. ”

The Washington Supreme Court ruled for the state, saying the Constitution’s directive that gives states the power to select members of the electoral college also means they can set the standards those electors must follow, such as living up to their pledge to support the state’s popular-vote winner.

A panel of the U.S. Court of Appeals for the 10th Circuit went the other way. It said Colorado’s control ended with deciding how electors from the state are chosen. From there, it said, the Constitution envisions that the 538 electors are free to vote their minds in deciding who should be president and vice president.

All but two states have winner-take-all systems, and 32, plus the District, require those running to be electors to pledge to support the state’s winner. Most simply expect the electors to honor the statewide result — the electors are chosen by the winning party, after all. Only 15 have penalties for punishing or replacing electors who break their word or have a change of heart.

Still, some states worried that faithless electors could determine the outcome. The 2000 election, for instance, was decided by five electoral votes.

Kagan acknowledged that history shows that a number of votes cast by rogue electors were counted by Congress. But none came close to affecting the election, she wrote.

“Since the founding, electors have cast some 180 faithless votes for either President or Vice President,” she wrote. “But that is 180 out of over 23,000. And more than a third of the faithless votes come from 1872, when the Democratic Party’s nominee (Horace Greeley) died just after Election Day. Putting those aside, faithless votes represent just one-half of one percent of the total.”

Kagan said both history and the “barebones” instructions in the Constitution weigh in favor of state restrictions.

The challenging electors said the Constitution’s words about “electors” voting in a ballot for president require them to have freedom of choice.

Kagan noted their argument that Alexander Hamilton, in the Federalist Papers, “praised the Constitution for entrusting the Presidency to ‘men most capable of analyzing the qualities’ needed for the office, who would make their choices ‘under circumstances favorable to deliberation.’ ”

But, she wrote, “even assuming other Framers shared that outlook, it would not be enough. Whether by choice or accident, the Framers did not reduce their thoughts about electors’ discretion to the printed page.”

Harvard law professor Lawrence Lessig had represented those asserting the independence of electors.

“When we launched these cases, we did it because regardless of the outcome, it was critical to resolve this question before it created a constitutional crisis,” he said in a statement. “Obviously, we don’t believe the court has interpreted the constitution correctly. But we are happy that we have achieved our primary objective — this uncertainty has been removed. That is progress.”

The cases were Chiafalo v. Washington and Colorado Department of State v. Baca.