Reza Zarrab, the chief government witness in a trial involving a billion-dollar scheme to smuggle gold for oil in violation of United States sanctions on Iran, testified on Thursday that his life had been threatened in a federal detention center in Brooklyn after he began cooperating with the prosecution.

A fellow inmate, saying he had been given instructions to kill him, pulled a knife on him, Mr. Zarrab said.

“I was about to lose my life,” he told the jury.

“He said that he had heard that I was cooperating — that’s why he was doing it,” Mr. Zarrab added.

As a result of the threat, he was removed from the Brooklyn jail and placed in the F.B.I.’s custody at an undisclosed location.