Senate leaders, working feverishly to ensure passage of a controversial bill that would allow Citicorp to open branches in Maryland, negotiated a compromise today that would restrict the giant New York bank to 20 branches in the state until 1988.

"Restricting the branches will give the Maryland banks the message that an out-of-state bank like Citicorp cannot expand on the scene overnight," said Senate President Melvin A. Steinberg (D-Baltimore County).

Steinberg, who worked for several hours today with other senators and Gov. Harry Hughes to draft the compromise, refused to discuss details of the legislation.

But he said he was "optimistic" about its chances for passing the Senate Finance Committee, which is scheduled to vote Saturday on the measure and a related regional-banking bill.

The compromise measure came three weeks after Hughes announced an agreement with Citicorp, the nation's largest bank holding company, under which the bank would open a large credit card service center in the depressed Hagerstown area in return for receiving broad banking powers in Maryland.

The agreement was criticized by many Maryland bankers who said they fear competition from Citicorp. Maryland bankers also said Hughes' agreement violated pending legislation that would establish four years of regional banking, during which banks such as Citicorp would be barred from expanding in Maryland because they are not based in one of the 14 states covered by the regional pact.

The House of Delegates earlier this week approved the regional banking bill and the companion measure that would carry out Hughes' agreement with Citicorp.

Those votes shifted the legislature's focus to the Senate finance panel, some of whose members have been outspoken critics of the Citicorp agreement.

In an effort to mollify those senators, Steinberg coordinated a compromise with committee chairman and legislative ally Dennis F. Rasmussen (D-Baltimore).

The key element of the compromise, according to three officials familiar with it, is one that would restrict banks such as Citicorp to opening only 10 branches per year starting in mid-1986. Such banks also would have to create 1,000 jobs and open a $25 million facility in Maryland, requirements which Citicorp would satisfy with its Hagerstown proposal.

Benjamin Bialek, an aide to Hughes who worked with Steinberg and Rasmussen to craft the compromise, said, "We think we're pretty close" to an accord on the Citicorp measure. Bialek would not comment further.

One early supporter of the Citicorp agreement in the Senate said he was satisfied with the compromise, saying that despite the limits on branch openings, the bill "is still tilted in Citicorp's favor."