Corrupt ex-Assembly Speaker Sheldon Silver was slammed with 12 years behind bars Tuesday — after the judge questioned whether the disgraced pol traded his clout for sexual favors.

Silver — one of the most powerful politicians in the state before his arrest last year — was convicted of netting more than $5 million in kickbacks in business schemes. But the feds have said they also uncovered evidence of ​the long-married ​Silver keeping two mistresses, including a lobbyist and former beauty-queen assemblywoman.

“Did a lobbyist have preferred access because she was a better lobbyist than her competitors, or was it payback for a personal relationship?” Manhattan federal Judge Valerie Caproni said before sentencing Silver.

“Those sorts of doubts end up corroding trust in government, and that, Mr. Silver, is discernible harm to the people o​​f New York,” the judge scolded.

In addition to the prison term, Caproni ordered Silver to fork over nearly $5.2 million of his ill-gotten gains and another $1.75 million in fines.

The disgraced ex-pol received two prison terms: 12 years for the six criminal counts against him, including mail and wire fraud and extortion, and another 10 years on a seventh count involving money-laundering. The terms will run concurrently.

Silver must surrender to begin serving his sentence July 1.