The Supreme Court, in a 5-4 decision on Thursday, ruled that federal courts cannot block partisan gerrymandering.

“We conclude that partisan gerrymandering claims present political questions beyond the reach of the federal courts,” Chief Justice John Roberts wrote in the majority opinion for the court.

The justices were weighing two cases from Maryland and North Carolina, where there were allegations that district maps were drawn to benefit one political party.

“Federal judges have no license to reallocate political power between the two major political parties, with no plausible grant of authority in the Constitution, and no legal standards to limit and direct their decisions,” Roberts said.

Justice Elena Kagan, who was joined in the dissent by Justices Ruth Bader Ginsburg, Stephen Breyer and Sonia Sotomayor, said that for the first time, “this Court refuses to remedy a constitutional violation because it thinks the task beyond judicial capabilities.”

“None is more important than free and fair elections. With respect but deep sadness, I dissent,” she wrote.