As a jury was expected to hear closing arguments Thursday in his third murder trial, Rick Morrocco Williams decided to plead guilty to lesser charges in the 2010 deaths of two of his roommates.

Williams, 28, accepted 20 years in prison on two counts of voluntary manslaughter. He had faced two murder charges, each of which were punishable by 30 years to life behind bars if he had been convicted.

It was an unexpected move for a defendant who saw two mistrials, including one last year in which the jury couldn't agree on a verdict. The third could have ended in a mistrial as well after the judge faulted a prosecutor for not divulging certain information before the trial this week.

Williams took the witness stand in his own defense. He described to the jury Wednesday how 58-year-old Nathaniel Lonnie had attacked him with a sword and 44-year-old Angie Ferguson with a box cutter.

He said he feared for his life when he shot each of the roommates once in the head Dec. 31, 2010, in the living room of a Durant Avenue home in North Charleston.

After attorneys discussed a deal Thursday morning, when they were expected to offer closing arguments, 9th Circuit Judge J.C. Nicholson sentenced Williams to 20 years on each charge. He will serve them concurrently in a state prison, according to sentencing documents.

He will get credit for the more than three years he has spent in jail while awaiting his three trials.

His first trial ended in a mistrial in 2012 after a juror failed to disclose certain information.

A year later, in February 2013, the jury was hung, and a judge declared another mistrial.

Nicholson considered a mistrial in the proceeding this week, too, after Assistant Solicitor Greg Voigt was found in violation of evidence disclosure rules.

During testimony Tuesday, a North Charleston Police Department detective revealed to the jury a statement that Williams had allegedly made to the police about not being afraid of Lonnie. Voigt had thought that the information had been given to Williams' public defender, Beattie Butler, at some point in the past two trials. A different prosecutor had handled those attempts.

Butler, though, said it was news to him and asked for a mistrial.

Nicholson instead opted to instruct the jury to ignore that portion of the detective's testimony when they started deliberating.

Because of the plea, though, the jury never got to that point.

Reach Andrew Knapp at 937-5414 or twitter.com/offlede.