The state’s highest court barred ethics investigators Thursday from asking embattled Boston ­Municipal Court Judge Raymond Dougan how he reached individual decisions during his 21 years on the bench, ruling that judges cannot be forced to explain their inner thinking to anyone.

In a unanimous decision, the Supreme Judicial Court created an absolute “judicial deliberative privilege” for the first time in Massachusetts. It will allow judges to keep their notes secret and to refuse to answer questions about how they ­arrived at their decisions.

“We conclude that although holding judges accountable for acts of bias . . . is essential, it must be accom­plished without violating the protection afforded the deliberative processes of judges,’’ wrote Justice Robert J. Cordy.

This privilege, Cordy wrote, will allow judges “to decide cases on the law and the facts as their best judgment dictates, without fear or favor.”

Dougan had appealed to the Supreme Judicial Court after the Commission on Judicial Conduct sought to delve into his decisions by interviewing him and reviewing his personal notes and diaries on dozens of cases.

The commission and its ­appointed special counsel J. William Codinha have been inves­tigating allegations by Suffolk District Attorney Daniel F. Conley that Dougan, first justice of the court that covers much of downtown, is biased against police and prosecutors. Conley filed a 61-page complaint with the SJC and the commission in December 2010.

Conley criticized the high court decision Thursday, saying that it gives judges in Massachusetts, who are already entitled to serve until age 70, even more job security.

“Judges here have long been afforded great protections to shield them both from political pressures and interference so they can do their jobs faithfully and without bias,” he said. “But everyone in government, includ­ing judges, must be account­able to someone.”

A 2011 Globe review found that prosecutors challenged Dougan’s decisions more often than those of any other sitting Boston Municipal Court judge. In addition, appeals courts reversed or modified ­Dougan’s rulings more than those issued by other judges.

In one case, Dougan dismissed drunken driving charges against Daniel Quispe, a native of Peru, even though ­Boston police said his blood-alcohol level was twice the legal limit. Dougan said he was serving “public justice” by dropping the charges because Quispe faced possible deportation if convicted.

The SJC struck down ­Dougan’s decision, finding that Dougan’s personal views on immi­gration law “are irrelevant and undermine the principle of separation of powers.”

In all, the commission sought to review 51 cases decided by Dougan, 24 cited by ­Conley, four additional cases described by the Globe, and 23 others the commission uncovered during its yearlong inves­tigation.

The commission can continue its investigation and can ask Dougan factual questions about the cases or his background, the high court ruled, but it may not ask what his thinking was in reaching individual decisions.

In its ruling, the judges said that judicial privilege had been implicit in previous decisions, but had never before been formally spelled out.

Conley said the decision will allow bad judges to remain on the job.

“If a judge ever shows racial bias, bias against female attorneys, or bias against same-sex partners in Family and Probate Court, this decision provides a powerful shield that will be used to keep him or her on the bench,” Conley said in his statement. “We must take very seriously how decisions such as the one issued today can undermine popular support for an independent judiciary. “

The high court sided with the commission on one point, allowing investigators to ­expand their ­inquiry to include the 23 cases turned up by commission officials.

The commission, which does its work in secret, has not confirmed it is investigating Dougan, whose name was never mentioned in the ruling and was blacked out in other court documents.

At a hearing before the high court in April, Codinha, the commission’s special counsel, argued that the commission is the only agency that can truly hold judges accountable for their ­decisions.

He could not be reached for comment Thursday.

Dougan’s lawyer, Michael Keating, said he was “very pleased” with the decision, saying that it “reinforces the independence of the judiciary.”

The ruling does not hamper the commission’s ability to do its job, he said.

“The Judicial Conduct Commission for years has investigated judges and issues of judicial misconduct and has never had to employ the device of asking the judge to disclose their thought processes and turn over notes,” he said.

The Dougan case had sparked intense interest among other judges and defense lawyers, who rushed to the judge’s side, accusing Conley of trying to intimidate judges who ruled against him. They argued that Dougan was simply exercising his judicial discretion.

“If we have to explain why a decision was reached, at the risk of alienating this group or that group, this will impact mightily on independence,” said J. Owen Todd, a former ­superior court judge who wrote a brief in the case on behalf of several retired judges.

Martin W. Healy, chief legal counsel for the Massachusetts Bar Association, which also filed a brief supporting ­Dougan’s stance, said the decision will “help prevent parties from going on unnecessary and burdensome fishing expeditions.”

“Judges must be free from overly broad intrusion and unnecessary pressure from disgruntled litigants,” Healy said.

Paul F. Walsh, Bristol district attorney from 1991 to 2007, predicted the ruling will make it much more difficult for the commission to prove its cases.

“The commission can ­inquire into all sorts of matters, but when they need evidence, they meet a stone wall,” Walsh said. “Why even have a commission then?”

Judges shouldn’t need any special protection and should welcome an opportunity to defend their decisions, he added.

“If you have nothing to hide, then don’t hide anything,” said Walsh.

Andrea Estes can be reached atestes@globe.com. John R.Ellement can be reached at ellement@globe.com.