On the so-called dark web, drug dealing and other illicit sales have thrived in recent years, the authorities have said, through hidden websites like Silk Road and hard-to-trace digital currencies like Bitcoins.

On Monday, the government charged that in the shadows of an undercover investigation of Silk Road, a notorious black-market site, two federal agents sought to enrich themselves by exploiting the very secrecy that made the site so difficult for law enforcement officials to penetrate.

The agents, Carl Mark Force IV, who worked for the Drug Enforcement Administration, and Shaun W. Bridges, who worked for the Secret Service, had resigned amid growing scrutiny, and on Monday they were charged with money laundering and wire fraud. Mr. Force was also charged with theft of government property and conflict of interest.

A criminal complaint unsealed on Monday in federal court in San Francisco outlined the allegations against the two former agents.

While investigating Silk Road, Mr. Force “stole and converted to his own personal use a sizable amount of Bitcoins,” the digital currency that was used by buyers and sellers on the website and which he obtained in his undercover capacity, the complaint said.

“Rather than turning those Bitcoin over to the government, Force deposited them into his own personal accounts,” it added.

Mr. Bridges, meanwhile, who was described as a computer forensics expert, diverted to a personal account more than $800,000 in digital currency that he gained control of during the Silk Road investigation, the authorities said.

The complaint described both former agents as members of a Baltimore-based task force that investigated Silk Road. The website had been the subject of investigations in several cities. A Manhattan-based investigation ultimately led to the filing of charges against the website’s founder, Ross W. Ulbricht, who was convicted last month on numerous counts.

The Baltimore investigation resulted in an indictment of Mr. Ulbricht on conspiracy and other charges, but that case has remained pending and the evidence in support of it was kept out of the New York trial.

Mr. Ulbricht’s lawyer, Joshua L. Dratel, said on Monday that shortly before the trial, the government disclosed “only a portion of what is revealed in this complaint,” and over the defense’s objections, “aggressively moved to preclude at trial any reference to Agent Force’s activities.” The judge granted the government’s request.

“It is clear from this complaint that fundamentally, the government’s investigation of Mr. Ulbricht lacked any integrity and was wholly and fatally compromised from the inside,” Mr. Dratel said.

The United States attorney’s office in Manhattan declined to comment. But court documents unsealed Monday show the office argued that Mr. Force played no role in the Manhattan-based investigation, which the office said had “proceeded on a separate and independent track” from the Baltimore one.

Moreover, the office argued, “from the outset, the government has made clear that the investigation” of Mr. Force “concerns only possible corruption” on the agent’s part “rather than anything suggestive of the defendant’s innocence.”

Mr. Force had been employed as a D.E.A. special agent for about 15 years; he resigned in May 2014, shortly after the investigation into his activities began, the complaint says. Mr. Bridges had been a special agent of the Secret Service for about six years until he abruptly resigned on March 18, after learning he was a subject of the investigation, it says.

Mr. Force, 46, was arrested in Baltimore on Friday and remained in custody there on Monday pending a detention hearing on Thursday, a Justice Department spokesman said. Mr. Force’s lawyer did not immediately return a call seeking comment.

Mr. Bridges, 32, of Laurel, Md., surrendered to the authorities in San Francisco and was released on bond by a magistrate judge there on Monday, his lawyer, Steven H. Levin, said. “Mr. Bridges maintains his innocence and will fight these charges in the appropriate venue at the appropriate time,” Mr. Levin added.

When charges were announced against Mr. Ulbricht in October 2013 and the website was shut down, the authorities called Silk Road “the most sophisticated and extensive criminal marketplace on the Internet.”

Several thousand drug dealers and other vendors used the site from January 2011 through its closing to sell hundreds of kilograms of illegal drugs and other illicit goods to more than 100,000 buyers, according to charges filed in Manhattan.

The site generated over $213 million in revenue during that period, and Mr. Ulbricht, operating under the pseudonym Dread Pirate Roberts, took millions of dollars in commissions, federal prosecutors in Manhattan charged.

Much of Silk Road’s allure to buyers and sellers was anonymity: The website operated on a hidden part of the Internet, out of the glare of law enforcement officials, and transactions were made in Bitcoins, which can be as hard to trace as cash.

Mr. Dratel, the defense lawyer, argued during the trial that his client was not Dread Pirate Roberts, the name of a character in the book and movie “The Princess Bride.” He conceded that Silk Road had been his client’s idea, but that Mr. Ulbricht had turned the website over to others before being lured back as a “fall guy” to be arrested.

Mr. Ulbricht was convicted on Feb. 4 of multiple counts; four of the charges, including distributing narcotics on the Internet and engaging in a continuing criminal enterprise, carry potential life sentences. He is to be sentenced on May 15.

At the trial, the government also accused Mr. Ulbricht of commissioning the murders of five people whom he saw as threats to his enterprise. Although the prosecutors said they found no evidence that anyone was harmed, they cited the murders for hire as evidence that Mr. Ulbricht was willing to use violence to protect his lucrative operation.

The agencies that investigated the Baltimore-based agents included the Internal Revenue Service, the United States attorney’s office in San Francisco, the Justice Department’s Public Integrity Section, the Federal Bureau of Investigation and the inspectors general for the Justice Department and Homeland Security, according to the complaint.

It charged that the former agents “abused their positions” to defraud the government and others “all for their own financial enrichment.”

Mr. Force, for example, created fictitious online personas that were not officially sanctioned by the investigation in order to communicate with Dread Pirate Roberts, the target of his investigation, the complaint says. Using one of those personas, Mr. Force sought to extort $250,000 from him in exchange for not providing the government with certain information.

Mr. Force, who used the undercover identity Nob in communicating with Dread Pirate Roberts, also created the fiction that he had sensitive law enforcement information that had been provided to him by a corrupt federal agent named Kevin who was part of the Silk Road investigation. In August 2013, for example, Dread Pirate Roberts paid Nob about $50,000 in Bitcoins for “ ‘Kevin’s’ inside law enforcement information,” the complaint says.

During the nearly two years Mr. Force was involved in the Silk Road investigation, the complaint said, he deposited about $776,000 — “an amount that represented solely his liquidation of Bitcoins” — into his bank accounts.

The complaint notes that in their communications, Mr. Force, writing as Nob, and Dread Pirate Roberts encrypted their messages on the agent’s instruction. But it says that a review of Mr. Force’s case file showed that it did not contain any of the keys or passwords needed to decrypt his messages, suggesting he was using encryption to conceal his own illegal activities.

“Even if encrypting messages to D.P.R. would make Nob more credible,” the complaint says, “the communications should have been documented, in deciphered form, and memorialized in the case file.”

Joseph Goldstein and Nicole Perlroth contributed reporting.

A version of this article appears in print on , on Page A19 of the New York edition with the headline: Inquiry of Illicit Website Spurred Agents’ Own Illegal Acts, Officials Say. Order Reprints | Today’s Paper | Subscribe