NIAGARA FALLS — Ryan S, Smith, the Niagara Falls man whose conviction for two home invasions, a shooting and an armed robbery was overturned because police used a Taser to force him to give a DNA sample, pleaded guilty to all of those crimes last week.

But in exchange, Niagara County Judge Sara Sheldon Farkas promised him a prison sentence of no more than eight years, about half of which Smith already has served.

It’s a big reduction from the 45-year sentence Smith, 25, received after a jury convicted him on 24 counts in August 2009. The sentence was later cut to 30 years by state prison officials applying the laws on sentencing for multiple felonies.

“It wasn’t our offer. It was the court’s prerogative,” said Paul C. Parisi, an Erie County assistant district attorney who served as a special prosecutor in the case.

“The DA couldn’t believe she made that offer, when you go through all the stuff that’s in the indictment,” said Joseph Terranova, the court-appointed defense attorney whom Smith kept trying to fire.

Farkas had promised the attorneys in her chambers two months ago that, if Smith pleaded guilty to all 24 counts, she would treat him as a first-time violent felon.

“She regrets making that sentencing commitment, but she wasn’t going to go back on it,” Terranova said. “I’m really happy with it.”

The guilty plea came as a surprise after a prolonged court session in which Smith was questioned at length about his ability to act as his own lawyer. Farkas has repeatedly refused to replace Terranova as Smith’s counsel.

The case was mired in further disputes over DNA evidence, and without that, Terranova believed, Parisi had insufficient evidence to convict Smith.

After refusing to submit to a court-ordered DNA swab, Smith in September 2008 was handcuffed on the floor of Niagara Falls Police Headquarters and zapped with a Taser so that officers could open his mouth to take a swab from the inside of his cheek.

The use of that force was reason for overturning the eventual conviction obtained from the DNA sample, the Appellate Division of State Supreme Court ruled last March.

Since then, Farkas has ordered Smith several times to give another DNA sample for use at his second trial, and Smith has refused.

Smith ordered Terranova to appeal Farkas’ DNA order, but first Smith needed so-called “poor person relief” to be spared from having to pay filing fees.

On March 5, the Appellate Division refused that relief, which Terranova said was a tip-off that the appellate judges thought the appeal had no merit. That angered Smith, who blamed Terranova for the loss and tried again to have him fired.

“We were arguing these things, and then Joe said he wanted to talk to his client,” Parisi said. Smith’s plea followed shortly thereafter. The sentence will be made official May 29.

“I was saying to him for weeks, ‘You won,’ ” Terranova said.