LOCKPORT – A Niagara Falls man who stole long guns in a burglary and was found to have a stolen handgun when he and a friend blundered into a drug raid accepted a plea deal Thursday.

Michael D. Ramos, 19, of Pine Avenue, agreed to plead guilty to two felonies and accepted a five-year prison sentence with three years of post-release supervision. The eight months he’s served so far in Niagara County Jail count toward that sentence, which County Judge Matthew J. Murphy III will make official March 14.

Ramos, who faced 30 years in state prison if convicted of all charges, also might have faced federal prosecution on gun possession charges. Assistant District Attorney Heather A. DeCastro said the U.S. Attorney’s Office agreed Thursday not to pursue the matter.

Murphy told Ramos that defense attorney Robert Viola “has given you a million-dollar defense. He’s represented you to the utmost of his ability.”

It took Viola about 90 minutes to make the deal Thursday, as the scheduled resumption of a hearing on Viola’s effort to have the burglary indictment dismissed on a technicality was replaced with negotiations in Murphy’s chambers.

As the conference continued, the scheduled witness in the hearing, prominent Niagara Falls defense attorney James J. Faso Jr., cooled his heels in the Courthouse rotunda.

He was supposed to testify on whether speedy trial deadlines were met in regard to Ramos’ theft of long guns and jewelry from a 19th Street home on Aug. 27 or 28, 2011.

Murphy said, “Plea negotiations that began last week were renewed, but with a deadline that if Mr. Faso testified, the plea would be withdrawn.”

The talks resumed after lengthy arguments on a defense effort to suppress the handguns seized from Ramos and co-defendant Michael S. Loverdi when they showed up at a Third Street apartment April 26. They arrived as seven Niagara Falls police officers were executing a search warrant for drugs inside.

Officers collared the pair and found stolen handguns in their pockets. Loverdi, 20, of 20th Street in the Falls, has pleaded not guilty to second-degree criminal possession of a weapon, fourth-degree criminal possession of stolen property, resisting arrest and second-degree obstructing governmental administration.

Murphy said he was probably not going to suppress the evidence.

After a conference with his mother and her fiancee, Ramos pleaded guilty to reduced charges of attempted second-degree burglary and attempted second-degree criminal possession of a weapon.

He was required to waive his right to appeal, drop allegations of ineffective assistance of counsel against Faso, and accept an order of protection for the burglary victim.

“For what it’s worth, I think it’s a just result,” Murphy said.