A federal judge got it right when he sentenced former state Sen. Leland Yee to serve five years in prison after he admitted participating in a variety of criminal schemes that involved taking bribes for using his political influence.

While giving Yee less than the eight years the prosecution had recommended, U.S. District Judge Charles Breyer also rejected Yee’s plea to serve his sentence under house arrest so that he could care for his ailing wife.

The judge told Yee, “The crimes that you committed have resulted in essentially an attack on democratic institutions. This is a serious, serious injury to a governmental institution.”

We couldn’t agree more.

When someone is elected to serve in public office, he or she is placed in a position of trust, and Yee managed to violate that trust in spectacular fashion.

This editorial board takes no particular pleasure in this sentencing. Yee was one of those few politicians who had often been a friend to media causes involving open meetings and open records. He won multiple awards bestowed by media groups for his supposed commitment to transparent government.

It is said that no matter how noble they appear, most human beings have a dark side. Based on his own admissions, that side of Yee was as dark as midnight.

Yee took a plea deal and in it admitted to accepting bribes to influence legislation for would-be medical marijuana businesses in the state, from an NFL team owner trying to exempt pro athletes from state workers’ compensation laws and from a software firm seeking government contracts. That firm just happened to be a creation of the FBI as part of a massive sting operation.

But perhaps the most shocking part of the whole sordid affair was Yee’s acceptance of money in an illegal international gun-running deal that was operating through the Philippines and his bizarre, mind-boggling argument that he accepted the money but didn’t have the ability to carry out his end of the deal.

How comforting.

The judge took particular note that involvement by Yee, a staunch advocate of gun control, was “hypocritical” and “unfathomable.”

It is difficult to disagree with that assessment.

The 67-year-old Democrat told the judge that he was ashamed of the crimes he had committed. That is, at least, a beginning. Several others caught up in the same FBI sting operation also have pleaded guilty and received prison time.

The operation also hooked reputed Chinatown crime boss Raymond “Shrimp Boy” Chow. He awaits sentencing after being convicted of racketeering in December after a lengthy trial.

Yee and the others have gotten what they deserve. The only positive purpose they can serve now is as object lessons for others in public life.