Rather than side with his secretary of state, Mr. Trump told them to work it out themselves, according to the two people briefed on the meeting. They spoke on the condition of anonymity because they were not authorized to discuss the matter.

In the end, no such prisoner swap took place. But the episode has opened a new chapter in Mr. Giuliani’s efforts to interject himself into the Trump administration’s diplomacy while at times representing clients with a direct interest in the outcome.

The Oval Office meeting occurred before Mr. Giuliani became Mr. Trump’s personal lawyer for the special counsel’s Russia investigation. In recent weeks, Mr. Giuliani’s campaign to press Ukrainian officials to investigate the son of one of Mr. Trump’s political rivals, former Vice President Joseph R. Biden Jr., has thrust him into the middle of the House impeachment inquiry. And on Wednesday, two of Mr. Giuliani’s associates in that campaign were arrested on charges of violating federal campaign finance laws.

[How did Mr. Giuliani get here? Watch a new episode of “The Weekly,” our television show, on FX.]

Mr. Giuliani, in an interview on Thursday, defended his actions in the gold trader case, which were first reported on Wednesday by Bloomberg.

Mr. Giuliani, well known for his hawkish views on Iran, said he had been willing to represent Mr. Zarrab because the proposed prisoner swap would have secured the release of an American pastor who was being held in Turkey on terrorism-related charges the United States considered fabricated.