The federal judge presiding over the case against a D.C. businessman behind an illegal, off-the-books effort for Mayor Vincent C. Gray ordered prosecutors to publicly name the mayor in court, finding that Gray’s campaign was central to the case.

The fact that Gray was identified in open court during a hearing in March for businessman Jeffrey E. Thompson prompted criticism from the mayor’s supporters in part because the city contractor’s allegations about the mayor came just weeks before the April Democratic primary in which Gray was defeated.

Gray has not been charged with any crime, and prosecutors told the judge that it would be potentially unfair to name him during the hearing, according to a court order unsealed Monday. The office of U.S. Attorney Ronald C. Machen, Jr. wanted to identify Gray only as “Mayoral Candidate A,” according to the opinion.

But U.S. District Judge Colleen Kollar-Kotelly ordered the government to identify the mayor, writing that Gray and his campaign were integral to the misconduct that Thompson acknowledged in his plea agreement with prosecutors.

“Mr. Gray and his campaign are not extraneous, but ‘necessary, material, [and] relevant’” to Thompson’s conspiracy to subvert campaign finance laws, the judge wrote.

Thompson pleaded guilty in March to pumping more than $600,000 into a secret 2010 campaign on Gray’s behalf, and the former city contractor said that the mayor personally asked him to finance the effort. Gray has accused Thompson of lying and long maintained that he did nothing wrong.

In explaining her decision, the judge noted that Machen’s office had previously said publicly that it was investigating Gray’s 2010 mayoral campaign. Kollar-Kotelly also wrote that she had previously required prosecutors to identify Gray during a hearing for the mayor’s former adviser Vernon Hawkins, who pleaded guilty to misleading FBI investigators.

At a press conference following Thompson’s plea hearing in March, Machen did not identify Gray by name. Justice Department policy recommends against identifying people who have not been charged with a crime.

But Machen was criticized by Gray’s supporters for his remarks that some viewed as a message to the mayor. He urged Thompson’s collaborators to “come forward and own up to your conduct.”

Get updates on your area delivered via e-mail