Legislation to transfer St. Elizabeths mental hospital from the federal government to the District by 1991 ran into difficulties in the Senate yesterday, but Senate staff aides said they thought they could be resolved.

Sen. Thomas Eagleton (D-Mo.), ranking minority member of the Senate Governmental Affairs subcommittee on the District, wanted to add an amendment to the measure that would require that land the city government does not use for mental health purposes revert to the federal government, congressional staff aides said.

D.C. Mayor Marion Barry was on the phone and on Capitol Hill lobbying hard on the measure yesterday. He met with Eagleton last night to try to work out an agreement, according to staff aides.

It appeared an agreement had been reached and that the measure would be brought up today, Ed Darrell, spokesman for the Senate Labor and Human Resources Committee, said later.

A single senator can prevent legislation from coming to the floor of the Senate, and there was such a "hold" on the bill yesterday, congressional aides said. This can be lifted after a senator's objections are met.

The House earlier this week passed the compromise St. Elizabeths measure, negotiated between the Reagan administration, the city and the hospital employes union over recent months.

Time is running short in the 98th Congress. If the Senate amends the measure, it must go back to the House for further action before it can be sent to the president for his signature. If the city objected to the bill as passed by the Senate, the House probably would not approve it, House aides said.

The White House supports the compromise bill passed by the House.

The compromise measure would transfer the St. Elizabeths property and operations to the city in October 1987. The federal government would pay a total of $219 million over a transition period ending in 1991.

The federal and city governments have been squabbling over their respective shares of responsibility at St. Elizabeths for years, and the hospital has faced a series of financial crises as the two governments have tried to get one another to pay more of the costs.

A $20 million extra federal payment for fiscal 1985, in the D.C. fiscal 1985 appropriations bill which is still awaiting final congressional action, was made contingent on Congress approving a final resolution on the future of St. Elizabeths.