Hospitals treating some of the nation's neediest patients will be spared billions of dollars in Medicare cuts by the Clinton administration, officials said yesterday.

Hospitals in Delaware, Hawaii, Massachusetts, Missouri, New York, Oregon, Tennessee and Vermont are affected. Altogether, the cuts could have meant some $2 billion over five years, officials said.

First lady Hillary Rodham Clinton, who is preparing to run for the Senate in New York, has been among those pushing for money to be restored to struggling teaching hospitals. New York's teaching hospitals train more doctors than any other state and serve some of the state's poorest residents.

The dispute stemmed from confusion over who counts as a Medicaid patient. Hospitals handling a large share of low-income and often uninsured patients are reimbursed for the care in Medicare payments. The reimbursement is based on a complicated formula that includes the Medicaid caseload.

Federal officials said some states had been counting certain people erroneously. Hospital officials said they thought they had been following the law.

Hospitals were initially told they would have to repay the extra $1 billion they had received in Medicare overpayments, but that changed in October due, in part, to a vigorous lobbying effort by three New York Democrats, Sens. Daniel Patrick Moynihan and Charles E. Schumer and Rep. Charles B. Rangel. Hillary Clinton sat in on a meeting the New Yorkers had with top officials at the White House.

The agreement reached yesterday with Health and Human Services Secretary Donna E. Shalala means that the funding system will stay the same, so that the hospitals will not see a sudden dip in their Medicare payments.

The hospitals are still fighting the billions of dollars in cuts from the federal Balanced Budget Act of 1997, although the administration agreed in November to soften those cuts somewhat.