Massachusetts legislators approved a bill calling for sweeping changes to the state's criminal justice system early Friday.

The Democratic-controlled Senate voted 27-10 in favor of the measure around 1:30 a.m. Friday morning, after many hours of debate over the amendments proposed in the legislation.

Such reforms include the repeal of mandatory minimum sentences for low-level drug offenses, a stricter set of guidelines for judges regarding the bail system, raising the age at which someone can be charged in adult court, and allowing for the compassionate release of elderly or weak inmates.

The bill also proposes allowing low-income defendants to pay lower court fees and fines, to eliminate what Senate President Stan Rosenberg's office calls a "modern day 'debtor's prison.'" Statutory rape law would also change under the legislation, which would legalize sex between teenagers on the basis of age difference rather than the ages themselves.

"It's time Massachusetts joins the national let's get smart on crime movement," Rosenberg (D-Amherst) said in a statement. "This bill protects public safety and makes commonsense reforms while improving outcomes with our precious tax dollars."

Advocates for the bill believe the state has long-needed to change the process to address recidivism and over-incarceration.

But in a letter sent to Rosenberg and Judiciary Committee Chairman Will Brownsberger earlier this week, nine of the 11 district attorneys in the Commonwealth opposed the large-scale overhauls included in the legislation.

"There are aspects of the bill which we believe hold out promise and which we embrace," the letter says.

"But still feel that too many aspects of the bill throw it far out of balance. This undermines the cause and pursuit of fair and equal justice for all, largely ignores the interests of victims of crime, and puts at risk the undeniable strides and unparalleled success of Massachusetts' approach to public safety and criminal justice for at least the last 25 years."

Northwestern District Attorney David Sullivan and Middlesex District Attorney Marian Ryan were the only two district attorneys not to sign the letter.

The bill now goes to the House of Representatives for consideration.