David Kramer, the then-Sen. John McCain aide who leaked the discredited Christopher Steele dossier on President Trump, testified in a libel case that he spread the unsubstantiated anti-Trump material all over Washington during the presidential transition.

Mr. Steele, a former British spy, testified in the same case that he relied on an internet gossip page to try to verify one of his key charges.

Mr. Kramer, a former State Department official and a Trump detractor, leaked the Democrat-financed dossier material to The Wall Street Journal, The Washington Post’s Fred Hiatt, CNN’s Carl Bernstein, National Public Radio, McClatchy news service and others, he said during his deposition in the libel case.

But his most momentous meeting was with Ken Bensinger of BuzzFeed. In Washington during the Christmastime holidays, he let Mr. Bensinger read the dossier. He then stepped away.

The reporter took cellphone photos. They ended up on Jan. 10, 2017, on BuzzFeed’s website, forever changing political history.

“He said he wanted to read them, he asked me if he could take photos of them on his — I assume it was an iPhone,” Mr. Kramer told the court in a libel case brought against BuzzFeed by a Russian entrepreneur.

U.S. District Court in Miami unsealed court files Thursday, marking the first time Mr. Kramer’s version of events has become public.

“I asked him not to. He said he was a slow reader, he wanted to read it,” Mr. Kramer testified. “So I said, you know, I got a phone call to make, and I had to go to the bathroom so I’ll let you be, because I don’t read well when people are looking at me breathing down my neck. And so I left him to read for 20, 30 minutes.”

“Were you aware that he had taken pictures?” an attorney asked.

“Not until January 10th,” he answered. “I was shocked.”

A rattled Mr. Kramer asked Mr. Bensinger to take down the dossier and leave his name out of it. Mr. Kramer was identified as the dossier leaker during the libel case’s discovery.

Mr. Kramer said Mr. Steele told him, “This wasn’t supposed to happen this way.” The Wall Street Journal exposed Mr. Steele as the author, sending him into hiding for weeks.

The McCain aide later amended his testimony. In a declaration, he said he had no problem with giving BuzzFeed a copy and provided copies to other journalists.

Mr. Kramer said he was pressed by Mr. Steele, who compiled the dossier, to spread the anti-Trump information to a variety of reporters. Mr. Steele himself was working reporters from London in his attempt to get the FBI to zero in on Mr. Trump before he took office.

Mr. Steele’s 35-page dossier claimed there was an “extensive conspiracy” between the Trump campaign and Russian intelligence to interfere in the 2016 election via computer hacking. That charge has not been borne out as special counsel Robert Mueller has not charged any Trump-related person with colluding with Russians to affect the election.

The dossier became a rally cry by liberals and Democrats, especially Rep. Adam B. Schiff of California, the top Democrat on the House Permanent Select Committee on Intelligence and now its chairman. He went on to read the unconfirmed dossier charges into the committee record in March 2017 as he vouched for Mr. Steele.

Mr. Steele was hired by the investigative firm Fusion GPS with money from the Hillary Clinton presidential campaign and the Democratic National Committee.

Republicans believe Mr. Steele’s work is a hoax and possibly Kremlin disinformation. The dossier explicitly cites Russian officials as sources for some of its more salacious details. Democrats rarely refer to the document.

Mr. Kramer told the story of how he came to own a dossier copy.

A Steele associate, Andrew Wood, told him and Mr. McCain about Mr. Steele’s explosive accusations during a conference in Canada.

The next step was for Mr. Kramer to travel to London that fall, rendezvous with Mr. Steele, read his claims and report back to the senator.

Mr. Kramer read the dossier at Mr. Steele’s home outside London. Mr. Steele said the allegations were “raw intelligence” that needed to be confirmed.

“He said that he had been hired to look into Donald Trump’s dealings in Russia, and that in the course of doing so, he came upon material that indicated that there were close ties between the Trump Campaign and various Russians, and the possibility of compromising material on Mr. Trump,” Mr. Kramer testified.

“He explained that what was produced … needed to be corroborated and verified. He himself did not feel that he was in a position to vouch for everything that was produced in this,” he said.

Mr. Kramer said Mr. Steele disclosed his Russian sources to him. He didn’t disclose them during the deposition.

By November, Mr. Steele sent a secure message to Washington that included 16 of the dossier’s 17 memos. Mr. McCain then handed the material to then-FBI Director James B. Comey. By that time, the FBI had obtained the information directly from Mr. Steele and from operatives of the Clinton campaign.

Mr. Steele, whose mission was to sink the Trump campaign and then his presidency, believed Mr. McCain’s involvement would give “the FBI additional prod to take this seriously,” Mr. Kramer testified.

“I shared with [Mr. McCain] the document, and he took some time to review it, he asked me what I thought he should do, and I suggested that he provide a copy of it to the Director of the FBI and the Director of the CIA,” Mr. Kramer testified.

The libel lawsuit was brought by Russian businessman Aleksej Gubarev. Mr. Steele accused him of conducting the hacking into Democratic Party computers — a charge the Russian denied from the start.

Mr. Steele said the charge came from unsolicited information and that he tried to verify it on an internet site called CNN iReport. Mr. Steele testified that he relied on an article on XBT, Mr. Gubarev’s firm, published on July 28, 2009.

Mr. Steele was asked by Mr. Gubarev’s attorney, Evan Fray-Witzer, “Do you understand that they have no connection to any CNN reporters”?

“I do not,” he answered.

The attorney added, “Do you understand that CNN iReports are or were nothing more than any random individuals’ assertions on the internet?”

Mr. Steele: “I obviously presume that if it is on a CNN site that it has some kind of CNN status.”

Mr. Gubarev’s lawsuit was dismissed by Judge Ursula Ungaro, who ruled that BuzzFeed was entitled to report on the dossier under the First Amendment’s free press guarantees — thus shielding it from U.S. libel laws — because the FBI used it in its investigation.