A Richmond man who was arrested after a shooting at a San Rafael nightclub was expected to be released from jail Friday after accepting a plea offer for substantially reduced charges.

Lemar Durell Dean, 28, who was a few weeks away from a scheduled trial on felony gun charges, admitted to a misdemeanor gun possession charge. The prosecution offered the plea deal on the day a judge was expected to rule on Dean's motion to suppress the evidence.

Dean's lawyer, Deputy Public Defender Michael Coffino, argued that investigators found the gun during an unconstitutional search of Dean's Mercedes-Benz.

"No one ever alleged that Mr. Dean was involved in the shooting," Coffino said Friday. "He was simply caught up in a police dragnet that was the subject of our motion to throw out the evidence. If Mr. Dean hadn't been released today we were ready to go straight to the court of appeal."

Dean could have faced up to six years in prison under the original charges.

The shooting, which remains unsolved, occurred early Nov. 23, 2012, at Club 101 on Francisco Boulevard West. San Rafael police said a fight inside the club spilled out into the parking lot, resulting in a melee and shooting that injured two men in a crowd of about 100.

In the ensuing chaos, police and sheriff's deputies blocked off the club's parking lot and questioned people trying to leave the area. Dean was stopped and questioned as he was driving through the traffic checkpoint police had established.

According to Coffino's defense motion, Dean was cooperative and courteous, did not appear intoxicated, and was not suspected of any vehicle violations. Authorities searched the car without Dean's consent and eventually found a handgun behind an armrest.

Dean was arrested because he had a prior felony conviction — a first "strike" in 2005 for shooting at an occupied home in Alameda County — and was prohibited from possessing a gun. He was released on bail while the Marin County District Attorney's Office reviewed the case.

Prosecutors eventually charged him with gun-related felonies but did not charge him with shooting the two victims at the club. He was arrested again last December to face the charges, and his bail was set at $270,000.

"Due to major evidentiary issues, he was allowed to plead to a misdemeanor for a jail sentence which included his time in custody since his arrest in December and conditions of probation including but not limited to waiver of search and seizure rights," Chief Deputy District Attorney Barry Borden said Friday.

A second man at the club that night, Maurice Kirkpatrick of Oakland, was also arrested on similar weapons allegations. He was released on bail, but prosecutors have since filed charges and obtained a warrant for his arrest.