A federal judge handed a legal victory to drug maker Hospira Inc. by suspending the U.S. Food and Drug Administration's decision this week to allow the marketing of certain generic copies of Hospira's top product, the sedative Precedex.

The judge, however, subsequently suspended the portion of his order stating that the FDA had to recall any generic Precedex already sold or distributed. Mylan Inc. said this week that it began shipping generic Precedex to the market on Monday.

The legal twists and turns arose after Hospira took the unusual step of filing a lawsuit to challenge the FDA's approval this week of generic copies of Precedex, saying the FDA decision would allow generic companies to violate Hospira's patent. Hospira is trying to preserve its market exclusivity for Precedex, which accounts for about 11% of the company's $4 billion of annual sales.

The drug is approved to sedate patients with breathing tubes in an intensive-care setting, as well as patients without breathing tubes before and during surgeries and other procedures.

A Hospira patent due to expire in 2019 covers the use of Precedex for sedation in an intensive-care unit, while other patents have already expired.

The FDA on Monday approved generic versions of Precedex with prescribing labels that omit information about the intensive-care unit use and only include information about the drug's use in other settings.

In a lawsuit filed in U.S. District Court in Maryland on Tuesday, Hospira argued that the FDA's decision was unlawful because some of the uses remaining in the prescribing labels for generic Precedex would violate Hospira's patent.

The FDA said it doesn't comment on pending litigation.

On Tuesday, U.S. District Judge George Jarrod Hazel issued a temporary restraining order that suspends the FDA's decision that it had the authority to approve generic versions of Precedex with the modified prescribing labels, effective until Sept. 2. The judge said the potential harm suffered by Hospira from the immediate availability of generics would far exceed what would be suffered by the FDA or Mylan.

The judge also initially ordered the FDA to recall any generic Precedex that was already sold or distributed, and to reverse the FDA approval of generic Precedex. But on Wednesday the judge suspended that portion of his order, at Mylan's request. Mylan had already started selling its product using the generic name for Precedex, dexmedetomidine hydrochloride, following FDA approval on Monday. Mylan argued that the FDA has no authority to conduct such a recall.

Drug companies often file so-called citizen petitions with the FDA seeking to block the agency's approval of certain generic drugs, but lawsuits against the agency are less common.

A Mylan spokeswoman declined to comment.

Hospira said in a regulatory filing that further court proceedings are expected in the next few days. The company didn't respond to inquiries.

Write to Peter Loftus at peter.loftus@wsj.com and Michael Calia at michael.calia@wsj.com