The government’s star witness in a trial that has angered the president of Turkey raped his cellmate with a cucumber while they were in lockup together, a shocking new lawsuit claims.

Reza Zarrab, 34, allegedly began raping and sexually abusing his cellmate and friend, Faouzi Jaber, 62, while they were detained together at the Metropolitan Correctional Center in downtown Manhattan, according to the Manhattan Supreme Court suit filed Thursday.

Zarrab is the rich former pal of Turkey’s president, Recep Erdogan, who copped a plea and agreed to cooperate with Manhattan federal prosecutors in the trial of Turkish banker Mehmet Hakan Atilla — against Erdogan’s wishes.

The prison rape allegations also emerged on Zarrab’s last day of testimony in the trial, where he has accused Atilla and other high-ranking Turkish officials, including Erdogan, of cooperating in a scheme to evade US sanctions against Iran.

“On two occasions Zarrab raped Jaber with his penis and on several other occasions Zarrab rammed his finger into Jaber’s anus,” Jaber’s lawsuit said. “On one occasion, Zarrab inserted part of what (Jaber) believes was a cucumber in Jaber’s anus,” causing him to bleed, the suit claimed.

Jaber, who is awaiting sentencing for trafficking drugs and guns to terrorist organization FARC, said Zarrab won him over by throwing money at him, including helping him pay for his defense, depositing cash in his commissary account and sending money to his family in Africa.

Their small cell “became a kind of a torture chamber” for Jaber, a cancer survivor with a “dangerous heart condition,” he claimed.

“Mr. Zarrab vigorously denies this outrageous and offensive allegation and will if necessary defend the action in court,” his criminal defense lawyer Ben Brafman told The Post.

On Thursday, Zarrab testified at Atilla’s trial that he was moved out of the prison system and into FBI custody following an attempt on his life over his cooperation with the feds.

“There was an individual who pulled a knife on me and I was about to lose my life,” he said. “He said that he had received instructions to kill because I was cooperating,” Zarrab said of the alleged attacker.

Erdogan has condemned Atilla’s trial as the work of his political enemy, a Muslim cleric living in Pennsylvania who he has also blamed for a coup attempt in Turkey last year.

Jaber’s lawyer, Alexei Schacht, denied that the lawsuit was politically motivated.

“This has nothing to do with Turkey. I have nothing to with Turkey,” Schacht the The Post. “The timing of this is coincidental.”

Zarrab has testified that he bribed Turkey’s former economy minister and that Erdoğan approved of their scheme to help Iran avoid US and UK sanctions.

He also confessed to bribing US prison guards in exchange for booze and cell phones.