It’s one thing to go to prison for a crime you didn’t commit, but it’s a whole ‘nother thing to do more than four years for a crime you weren’t even charged with.

A Brooklyn man in the mdist of an 18-year prison term was granted $75,000 bail today after an appeals court heard that the crimes he was convicted of had been dismissed before his trial even began.

“I’m happy,” said appeals lawyer Rita Dave, who took over Oswind David’s case after an appeal on different grounds failed. “My goal was to get him freed immediately. He should not have been sitting in jail.”

David, 31, was charged in March 2006 with attempted murder after an altercation with the extended members of his family while at a holiday party in Bedford-Stuyvesant, according to court papers.

He was also charged with four counts of first-degree assault: two for allegedly using a box-cutter, two for intending to disfigure his alleged victims.

Police said one of the alleged victims was slashed in the neck while the other was cut in the face and neck, requiring 70 stitches.

Brooklyn Supreme Court Justice Patricia DiMango threw out the two assault charges involving the box-cutter, saying the grand jury presentation was insufficient to support the charge. She told the Brooklyn DA’s office it could resubmit those counts to a grand jury, but that never happened and David went to trial on the other charges.

Amazingly, neither defense attorney David Epstein, nor two assistant district attorneys nor trial judge Cheryl Chambers, noticed that jurors were allowed to consider the two dismissed counts.

More amazing, in December 2006, the jury acquitted David, a native of Guinea, of all the other counts but convicted him of the boxcutter assaults, which earned him the prison term.

“I have no explanation,” said Dave, who successfully argued David should be freed during his appeal. “Nobody paid attention, I guess. It was really a breakdown at every level.”

She said she expects David’s family will raise the money quickly and he should be freed within a day or two. Prosecutors argued yesterday that David should remain in prison because the first-degree assault convictions cover the lesser charge of second-degree assault, which was part of the indictment.

There was no answer at the phone listed for the David family’s Canarsie home.