The Trump administration on Wednesday sued Gilead Sciences, a pharmaceutical company that sells H.I.V.-prevention drugs that can cost patients up to $20,000 a year, accusing the company of earning billions from research funded by taxpayers without paying taxpayers back.

The government said the company infringed upon patents owned by the Department of Health and Human Services, and had refused attempts by the department to license its patents and collect royalties. The company sells two drugs, Truvada and Descovy, that can be taken once daily to prevent H.I.V. infection, a strategy called pre-exposure prophylaxis, or PrEP.

Wider access to PrEP is central to the government’s goal, announced in February, to reduce new H.I.V. infections by 75 percent over five years, and to “end the H.I.V. epidemic in America” by 2030. Critics have said the drug’s lofty price tag has limited its accessibility to high-risk people with low incomes, thwarting the government’s efforts.

“Gilead must respect the U.S. patent system, the groundbreaking work by C.D.C. researchers, and the substantial taxpayer contributions to the development of these drugs,” Alex M. Azar II, the secretary of health and human services, said in a statement, referring to the Centers for Disease Control and Prevention. “The complaint filed today seeks to ensure that they do.”

In May, Gilead said it would donate enough medication to supply 200,000 patients with the drug for up to 11 years. But about 1 million Americans are estimated to be at risk for infection, and only about 270,000 people take the pills.

Gilead makes more than $3 billion a year on Truvada.

The lawsuit was cheered by some activists. PReP4All, a group that has pushed for wider access for the drugs, called it “a necessary first step to ensure access to effective H.I.V. prevention for everyone who needs it.”

“For nearly a decade, Gilead’s price gouging on PrEP has prevented hundreds of thousands of Americans from accessing this life saving medication, despite it being a taxpayer-funded invention,” the group said in a statement. “If H.H.S. is truly invested in ending the H.I.V. epidemic, it will use these patents as leverage to ensure that everyone who needs PrEP can get it.”

Gilead did not respond to a request for comment sent on Monday, but has previously said that the government’s patent claims are invalid, and that others had conceived of the concept of PrEP before the government. The Department of Health said hundreds of millions of dollars in taxpayer money went into research that led to the government patents. Currently, Truvada and Descovy are the only F.D.A.-approved drugs for H.I.V. prevention.

Descovy, approved in October, contains a new version of tenofovir, the active ingredient in Truvada, and was expected to effectively replace Truvada. But the approval excluded “individuals who have receptive vaginal sex,” as Gilead tested it only in men and transgender women. The F.D.A. will require the company to study the drug on cisgender women.

In Africa, generic Truvada costs about $60 per patient per year. Gilead has sued companies that have tried to bring generic versions to the United States, keeping them out of the market after secret settlements.