Voter fraud was one of ex-Bronx Assemblyman Nelson Castro’s tricks for gaining power, court papers obtained by The Post show.

Castro schemed to illegally register dozens of voters in his district ahead of the election that sent him to Albany and forged signatures on petitions to earlier seek office as a district leader.

Those revelations are spelled out in a deal Castro signed April 2 in which federal prosecutors agreed not to prosecute those crimes in return for wearing a wire in a probe of his political colleagues.

It’s the same document in which Castro agreed to resign from the state Assembly, and in which Bronx prosecutors agreed to drop state perjury charges for lying about the number of people registered to vote from his one-bedroom apartment.

Castro’s cooperation is critical to the case against Assemblyman Eric Stevenson, who was charged last week with promising to introduce legislation for a quartet of shady businessmen who wanted to open adult day care centers.

Castro, who was first elected to the Assembly in 2008, could not be reached for comment.