The Maryland Senate late Monday approved a measure to streamline the state’s method of setting bail by creating a new agency under the governor that would use computers instead of District Court commissioners to determine who should go free pending trial.

The vote capped several days of vigorous debate on an issue that was forced on the legislature after its highest court found that too many people were unnecessarily incarcerated pending trial, perhaps because they lacked adequate legal representation when they went before District Court commissioners.

Backers said the decision was a necessary step to address the court’s concerns, especially with time running out in the legislative session and the court’s decision to stay implementation of its rulings until this June. But critics said the legislature was making a bad decision worse.

“This is one of the most dangerous bills I’ve seen down here,” said Sen. Robert A. Zirkin (D-Baltimore County), who has instead urged lawmakers to overturn the court’s decision.

Sen. Christopher B. Shank (R-Washington) called the bill “the best solution forward” and argued the current system isn’t working all that well. He said the legislature can’t do nothing at this point.

“We’re playing chicken with the court,” Shank said. “Doing nothing at this stage is a recipe for disaster.”

The Maryland Court of Appeals, in DeWolfe v. Richmond, held that every defendant is entitled to legal representation at the earliest judicial proceeding, including bail hearings before commissioners, and that those who are too poor to afford legal counsel should be supplied with an attorney.

But lawmakers balked at the sizable cost to provide a public defender around the clock, seven days a week, to every defendant who needs one — particularly because Maryland’s system allows defendants duplicative bail hearings before District Court commissioners and District Court judges. Estimates of providing public defenders and other staff before a District Court commissioner and a District Court Judge in the current system have ranged as high as $55 million.

To address those issues, Sen. Brian E. Frosh (D-Montgomery), with the blessing of Gov. Martin O’Malley (D), Senate President Thomas V. “Mike” Miller Jr. (D-Calvert) and House Speaker Michael E. Busch (D-Anne Arundel), sponsored a bill that would take the bail decisions out of the hands of court commissioners.

Instead, a new pretrial services division would be created in the executive branch that would use statistical analysis to determine whether a defendant should be held without bail or released. Frosh argued that the system, which is in use in the District of Columbia, Kentucky and other jurisdictions, released more people. And yet those jurisdictions also found that fewer defendants failed to appear in court or re-offend while free pending trial. Frosh said the new division, which would begin with a pilot program, would cost $14 million to $16 million a year.

Backers played up the broad coalition of support that included prosecutors, local corrections officials, and public defenders. But opponents said the bill represented a drastic and misguided effort that, in the name of protecting defendants’ rights, would hand over decisions about their liberty to a computer operated by law enforcement.

But Sen. James Brochin (D-Baltimore County) said Maryland would be the first state where “you have a machine making a decision.”

Frosh, in urging the Senate to back his plan, warned that if the legislature failed to act, the Court of Appeals could order the state to begin providing free legal counsel to indigent defendants. He also said that could trigger a constitutional crisis between all three branches of government.

But critics said Frosh’s proposal would actually limit defendants’ rights more than the current system. Some warned about ceding too much authority to a computer controlled by the executive branch. Zirkin, during the debate last week, likened reliance on a computerized model to the sci-fi movie “Minority Report,” in which a specialized law-enforcement unit uses mutated human beings and machines to predict crimes and identify their perpetrators before the crimes happen.

“This is a small step away,” Zirkin said during Friday’s debate.

Instead, Zirkin has urged the General Assembly to pass a constitutional amendment that would undo the high court’s ruling. His proposed amendment, SB1114, is scheduled to be heard by the Judicial Proceedings Committee onTuesday.

Miller, meanwhile, said the House appears headed in a different direction and that both chambers have a long way to go before reaching compromise.