NEW YORK — Sheldon Silver, the former New York Assembly speaker who brokered legislative deals for two decades before corruption charges abruptly ended his career, was sentenced Friday to seven years in prison.

The punishment, announced by U.S. District Judge Valerie Caproni, was five years less than the 12-year sentence she gave to Silver after he was initially convicted in the case in 2015.

That conviction was tossed out by an appeals court, but the 74-year-old Democrat fared no better at a second trial this spring. A jury once again found him guilty of taking nearly $4 million in return for legislative favors he performed for a cancer researcher and real estate developers.

In a letter to the judge, Silver had begged for mercy. His lawyers had asked that he be given a shorter sentence with a community service component that would allow him to get out from behind bars.

"I pray I will not die in prison," Silver wrote, saying he was "broken-hearted" that he damaged the trust people have in government.

"The work that has been the focus of most of my life has become dirty and shameful," Silver had said in his letter. "Everything I ever accomplished has become a joke and a spectacle. ... I beg for your mercy so that I can somehow go out into the world again to atone to everyone I have hurt."

Prosecutors had argued that Silver “repeatedly corrupted the great power of his office for personal profit” and should get at least a decade in prison.

First elected in 1976, Silver served as speaker for 21 years, resigning after his 2015 arrest.

His sentencing comes 10 days after Dean Skelos, the former New York Senate leader, and his son, Adam, were convicted of extortion, wire fraud and bribery at a retrial for each of them.

Like Silver, the once-powerful Republican and his son also were granted a new trial after the Supreme Court narrowed public corruption law as it reversed the conviction of former Virginia Gov. Bob McDonnell. They were also convicted at a retrial.

Silver and Skelos were among a trio dubbed the “three men in a room” in Albany, a nod to the longstanding practice of legislative leaders and the governor negotiating key bills behind closed doors. Skelos served in the Senate from 1985 to 2015 and became Senate leader in 2008.

Over 30 New York state lawmakers have left office under a cloud of criminal or ethical allegations since 2000. More than a dozen have been convicted of charges including authorizing bribes to get on a ballot, diverting money meant for community programs into a campaign and skimming funds from contributions to a Little League baseball program.