TALLAHASSEE — The back-and-forth battle over secret redistricting documents ended Tuesday as the Florida Supreme Court ruled that 538 pages of emails, maps and planning documents of a GOP political operative must be allowed into the record in the ongoing redistricting trial — but only if the courtroom is closed.

The 5-2 ruling by the state's high court was a victory for the voters groups that are challenging the congressional maps drawn by the Legislature. The groups also are alleging that a "shadow" redistricting process was conducted by political consultants and operatives in an attempt to unconstitutionally influence the Legislature's drawing of the 2012 maps.

But the ruling also was a triumph for Pat Bainter, and his company, Data Targeting, who sought to shield his confidential conversations from the public. Trial court Judge Terry Lewis had ruled that Bainter's documents could remain confidential unless they were entered as evidence in the trial but the 1st District Court of Appeal reversed that decision and ordered the documents to remain sealed.

The plaintiffs in the case, led by the League of Women voters, asked the high court for an emergency review of their appeal and argued, in briefs that were kept under seal, that the documents should be opened and allowed in court.

The court noted that the "statewide importance" of the litigation and the "lack of Florida precedent" regarding the secret documents made it likely that the appellate court would have referred the issue to the high court. But, because the case is ongoing, the justices wanted time to determine whether the documents should be made public. The court ordered Lewis to "maintain the confidentiality of the documents by permitting any disclosure or use only under seal of the court and in a courtroom closed to the public."

The ruling protects Bainter in the event the documents are deemed "trade secrets," as his lawyers argue, but it also allows the trial — now in its second week — to continue. The judge has set a strict deadline of next Wednesday for completion of the case.

The First Amendment Foundation and some news organizations are reviewing the ruling to decide whether they will take a position on closing the courtroom in the case.

"This litigation is unique because it impacts the statewide operation of government and the validity of Florida's current system of government through the alleged unconstitutionality of the 2012 apportionment plan," the majority wrote in the opinion signed by Justices Barbara Pariente, Peggy Quince, Jorge Labarga and James E.C. Perry.

Justice R. Fred Lewis concurred with an opinion. Justices Ricky Polston and Charles Canady dissented, with an opinion.

The decision came even before the appeals court released its written opinion on the ruling it made Thursday. The DCA ordered the documents sealed but was expected to make its findings and determine the rule of law in a written opinion that has not yet been issued.

Polston blasted that order of events as "truly unprecedented" and chastised the majority as "simply guessing at what the First District's opinion will state as the basis for its ruling in order to engage in the active trial management." He also accused the court of unconstitutionally pre-empting the appellate court.

"In short, this Court has predetermined appellate error and awarded the petitioners full relief in the trial court by requiring admission of evidence," Polston wrote.

The majority noted that the appellate court was likely to have certified a question to the Supreme Court when it releases its expected opinion and their emergency action was "in order to maintain the status quo during the ongoing trial" and to "prevent any irreparable harm that might occur if the Petitioners are prevented from using the challenged documents."

The ruling will create some challenges for Lewis, who has allowed the trial to be broadcast daily on public broadcasting's Florida Channel.

Lewis was told of the ruling and the potential for a closed courtroom at the end of the redistricting hearing on Tuesday.

"I wasn't about to close it without someone telling me," the judge said.

Mary Ellen Klas can be reached at meklas@miamiherald.com. Follow @MaryEllenKlas on Twitter.

Correction: Justice Ricky Polston wrote the dissenting opinion. An earlier version of this story attributed the words to a different justice.