Federal safety regulators filed a lawsuit against Amazon on Wednesday that accuses the retail giant of refusing to recognize regulators’ authority to force the company to recall defective and unsafe products, setting up a fight over how much responsibility Amazon should take for the products it sells on its website.

The action by the Consumer Product Safety Commission comes after months of behind-the-scenes negotiations between regulators and Amazon as the agency tried to persuade the company to follow the CPSC’s rules for getting dangerous products off the market, according to a senior agency official who spoke on the condition of anonymity to comment on internal discussions.

The official said Amazon officials refused to acknowledge that the CPSC has the authority to compel the company to remove unsafe products.

A lawsuit was viewed as a last resort, the official added.

Amazon spokeswoman Cecilia Fan said in a statement that the company offered to expand its capabilities to handle recalls for products sold by Amazon and third parties.

“We are unclear as to why the CPSC has rejected that offer or why they have filed a complaint seeking to force us to take actions almost entirely duplicative of those we’ve already taken,” Fan said.

Amazon founder and executive chairman Jeff Bezos owns The Washington Post.

Amazon’s dominance in the retail world has presented increasingly difficult challenges for regulators and the courts. Most of the unsafe products identified by the CPSC were made by small, usually foreign companies selling their wares often exclusively on Amazon’s platform. With Amazon handling so much of the traditional retail transaction — marketing, handling, shipping, delivery and returns — the manufacturer seems to fade into the background.

For example, the lawsuit alleges that Amazon sold 24,000 faulty carbon monoxide detectors made by apparently Chinese companies, including one named WJZXTEK. After being alerted by CPSC staffers that the detectors did not work, Amazon stopped selling them, the lawsuit said. Amazon then contacted consumers with a refund offer. But the company declined to work with the CPSC on a safety recall. “Amazon’s unilateral actions are insufficient to remediate the hazards,” the lawsuit said.

The lawsuit also provides similar examples involving children’s pajamas that violated flammability standards and nearly 400,000 hair dryers sold without the mandatory devices to protect against electrocution.

Sen. Richard Blumenthal (D-Conn.), who previously has castigated Amazon for offering unsafe products in its marketplace, said in a statement that the CPSC filing sends “a clear message” to Amazon and other online marketplaces that “knowingly selling dangerous and defective products that imperil Americans will not be tolerated.” Blumenthal cited past instances of goods purchased from Amazon catching fire and injuring customers, adding that the company “must take responsibility for stemming the tide of hazardous products sold through its platform.”

Fan said Amazon takes “prompt action” when safety concerns about products sold on the site are raised. The CPSC’s filing notes that Amazon took action on nearly all the products in question after the CPSC’s warnings. Amazon didn’t take similar steps for the remaining products because the agency didn’t provide the company with enough information, Fan said.

In May, Amazon sent a letter to the CPSC offering to create a “Recalls Pledge” that called on “all online marketplaces to execute recalls for products sold in their online store by third party sellers.” The company said it would be the first signatory.

The pledge would not have had the regulatory power of the CPSC but would have called on online marketplaces to serve as the agency’s point of contact for recalls as well as develop mechanisms to hold unresponsive third-party sellers accountable.

Amazon became the nation’s largest online retailer in part by turning its store into an online bazaar where millions of third-party vendors sell their goods.

The company has prioritized vast selection, allowing merchants to sell on the site with scant vetting and letting sellers like the ones found by the CPSC operate. The company has said that among its screening processes, it uses machine learning technology to identify risky sellers as well as using investigators to review applications.

But Amazon has aggressively recruited Chinese sellers to make its catalogue of goods so extensive that rivals cannot match it. And those merchants sometimes sell goods that do not meet standards set by U.S. regulators such as the CPSC.

Some of the products the CPSC cites in its filing appear to be from Chinese manufacturers. And customers who have been injured by Chinese-made products purchased on Amazon have discovered that those merchants are effectively judgment-proof because they are outside the jurisdiction of U.S. courts. Some sellers have disappeared, leaving consumers unable to hold them accountable.

Nearly 60 percent of all physical goods sold on Amazon’s e-commerce marketplace come from third-party merchants.

But customers who have bought defective goods from the site have said they believed they were buying directly from Amazon, a company they thought would not sell unsafe products.

The CPSC is not alone in struggling to figure out how to treat Amazon.

In April, a California appeals court found that Amazon could be held liable in that state for burn injuries caused by an allegedly defective hoverboard sold by a third party on the marketplace, even though the e-commerce giant did not warehouse or ship the product.

But two months later, the Texas Supreme Court ruled that Amazon could not be held liable for the injuries of a toddler, who ingested a battery from an allegedly defective remote control sold on the Amazon site by a third party.

The CPSC voted 3 to 1 sue Amazon in administrative court, asking the company to work with the CPSC staff on recall actions.

Acting CPSC chairman Robert Adler said the Amazon case showed the agency’s rules needed to be updated because they were written before Amazon transformed the retail trade — before third-party sellers and online marketplaces became dominant.

“Clearly the current approach is not sustainable,” Adler said in a statement. “To continue product-by-product is like using an eyedropper to empty the ocean — ineffective, inefficient, and frustratingly insufficient to protect consumers.”