New York (CNN) Turkish President Recep Tayyip Erdogan personally intervened in a scheme that allowed Iran to dodge US and UN sanctions, a gold trader with ties to the Turkish government claimed in explosive court testimony in New York on Thursday.

It's the first time Erdogan has been named in the closely-watched US criminal case over Iran's violations of international sanctions and movement of billions of dollars.

The case's central figure, Reza Zarrab, an Iranian-Turkish gold trader, was arrested in Miami last year and has since been the case's top named defendant. There are eight other defendants facing similar charges.

He quietly cut a plea deal last month and admitted to defrauding the United States, money laundering, and bank fraud, according to court documents.

On Thursday, Zarrab testified in federal court about Erdogan's alleged role in Zarrab's scheme, which involved laundering funds from Iranian oil and gas sales through Turkish banks, including the state-run bank, Halkbank.

Zarrab testified that when the amount of money illegally flowing through Turkey's Halkbank became too much to handle, Erdogan approved getting two more Turkish banks involved: VakıfBank and Ziraat Bank.

Zarrab said he received this information from the government official he claims to have bribed to take part in the scheme, former Turkish economy minister Zafer Caglayan. Caglayan denied all allegations in a Turkish probe into these allegations that started in 2013.

On Thursday, Erdogan responded to Zarrab's testimony from Wednesday, saying Turkey "did the right thing" and did not violate US sanctions against Iran, according to CNN Turk.

"The prime minister of that time, Recep Tayyip Erdogan, and [then] Minister of Treasury Ali Babacan had given orders for them to start the trades, the banks," Zarrab said Thursday. CNN has sought comment from the Turkish government on Zarrab's testimony and is awaiting response.

In their court filings, the US government has not alleged that Erdogan cooperated in the scheme.

Recep Tayyip Erdogan, President of Turkey.

On Wednesday, Zarrab testified that he paid Caglayan more than 31 million Euros ($36.7 million) in bribes to help Iran launder money and dodge international sanctions. Caglayan denied all allegations in a Turkish probe into the claims, which started in 2013.

That probe was shut down after Turkish police and prosecutors in charge of it were accused of being supporters of Fethullah Gulen. Gulen is the Muslim cleric in self-imposed exile in the US whom Erdogan has accused of being behind a failed military coup to overthrow him in 2016. Gulen denied any involvement.

One of the police officers in the 2013 Turkish probe has since fled Turkey and will now serve as a witness in the US government's case, prosecutors said in court earlier this week.

For years, US and United Nations sanctions on Iran have kept that country from accessing billions of dollars stored in banks around the world. The tactic is meant to punish Iran for its attempts to develop nuclear weapons and threatening Israel and the United States.

Zarrab's detailed testimony, which surprised those in the courtroom, brings the criminal case's focus to top levels of the Turkish government — and may help explain why Erdogan has lambasted the American investigation. The Turkish government has sought the return of Zarrab. Erdogan loyalists view the Zarrab case being tried in New York as a political move against the President and his party.

Cash to CAG

On Wednesday, Zarrab testified about his role in helping Iran dodge sanctions to access money stuck in Turkish banks.

Zarrab recalled how he paired up with a jeweler in 2012 to devise a scheme in which they would trade gold for cash in order to launder billions of dollars for Iran. He told the court how money would traverse through nearly a dozen banks and shell companies and sometimes wind up in American banks — including Standard Chartered and others. They did this so that Iran could conduct international business through proxies and circumvent international sanctions.

"A few billion ... euros" were withdrawn in this scheme "under disguise of gold trade," Zarrab said.

In this courtroom sketch, Turkish-Iranian gold trader Reza Zarrab, center, testifies before Judge Richard Berman, right.

When a top official at Turkey's Halkbank refused to let Zarrab do that, Zarrab said he went to Caglayan -- then the economy minister -- to pressure Halkbank to play along.

Caglayan agreed to meet in person, and asked Zarrab details about the illegal deal and its profit margins, Zarrab testified.

"I can work with this, sharing profits 50/50," Caglayan said, according to Zarrab's testimony.

US federal prosecutors showed American jurors what they said were spreadsheets kept by Zarrab during the operation of his illegal trading business. In it were several payments marked "cash to CAG," a reference to Caglayan.

Nate Schenkkan, a Turkey analyst at the pro-democracy organization Freedom House who is watching the trial, told CNN this is the first time the public sees "the raw scale of the bribes and corruption."

Zarrab's witness testimony and documents displayed at trial "would show that this conspiracy to launder money for Iran was not a rogue operation. It would show the Turkish government at its very highest level understood what was going on — and approved of it," Schenkkan tsaid.

Zarrab is also testifying in this trial against the deputy general manager of Halkbank, Mehmet Hakan Atilla, who until recently was Zarrab's co-defendant. Atilla has pleaded not guilty.

Zarrab testified that he conducted these types of business deals for the National Iran Oil Company, and the scheme would move money between bank accounts at Halkbank that belonged to a major Iranian bank, along with the Turkish companies Botas, Tupras and others, before moving the money out internationally.

In essence, Zarrab painted a picture that portrayed Halkbank as a laundering tool within its own walls.

In a written statement, Halkbank denied the accusations: "Our bank did not do any illegal transfers about any country. There is no systematic or conscious violation in order to bypass the embargo."

Zarrab also testified that he engaged in a scheme to pull Iranian money out of Aktif Bank, the largest privately-owned investment bank in Turkey.

On a daily basis, Zarrab said he brokered the illegal movement of US $5-10 million of Iranian money out of Aktif Bank. But Zarrab claimed he lost the illegal business when the bank cut him out as the middleman and started doing it on its own.

The US connection

In testimony on Wednesday, Zarrab told the court he initially hired American lawyers to pursue some sort of "prisoner exchange" between the United States and Turkey -- an odd effort that failed.

It is unclear who would have been part of that prisoner swap. But the Turkish government has several Americans — jailed under suspicious circumstances — whom it sees as bartering tools with the United States, according to Schenkkan, the analyst.

Zarrab did not mention the lawyers by name in court, but after his March 2016 arrest he hired former US Attorney General Michael Mukasey and former New York Mayor Rudy Giuliani, a supporter of and former campaign advisor to US President Donald Trump.

Giuliani and Mukasey traveled to Turkey in February to meet Erdogan to seek a solution to the case, according to one of Zarrab's other lawyers.

In a filing in federal court made public in April, Giuliani said US and Turkish officials were "receptive" to resolving the case, Reuters reported.

"That receptiveness is hardly surprising when one considers that none of the transactions in which Mr. Zarrab is alleged to have participated involved weapons or nuclear technology, or any other contraband, but rather involved consumer goods, and that Turkey is situated in a part of the world strategically critical to the United States," Giuliani said, according to the filing.