The Senate last night repelled an effort to retain current tax benefits for federal retirees in its tax-overhaul package, virtually ensuring that they will begin paying taxes on their pensions sooner under the package that emerges from Congress.

And for the first time, the Senate went against the wishes of Finance Committee Chairman Bob Packwood (R-Ore.), voting overwhelmingly to strip from his panel's package a provision that would repeal an existing tax on foreign investments in U.S. real estate.

The amendment to preserve the benefits for government retirees, many of them federal workers, was offered by Sen. Paul S. Trible Jr. (R-Va.) and 10 other senators, including John W. Warner (R-Va.) and Paul S. Sarbanes (D-Md.), and was supported by Sen. Charles McC. Mathias Jr. (R-Md.). Trible said before the vote that he did not expect the amendment to pass, even though the provision "would undo years of financial planning for some 20 million Americans" and cause government workers to retire in droves to escape its effects. The vote was 57 to 42.

Trible, Warner, Sarbanes and the others proposed to raise the revenue lost by their amendment by reducing by $525 the income levels at which the top personal and corporate tax rates in the bill would take effect.

Packwood, in his most impassioned speech of the eight-day tax debate, said every interest had given up something in the effort to reduce tax rates, and that passage of the amendment could torpedo the sweeping legislation.

He and Sen. Bill Bradley (D-N.J.) warned that the offsetting provision was, in effect, a tax increase because more people would pay at the top tax rate if the income level pegged to that rate were reduced.

"We might as well call a spade a spade," Packwood said. "This is a tax increase on middle-income taxpayers in this country."

The Finance Committee package would require, starting in 1988, federal workers to begin paying taxes on their pensions immediately upon retirement, rather than receiving tax-exempt payments initially and taxable benefits in later years.

The House tax bill includes the same provision, although it would take effect sooner. An estimated 20 million government workers would be affected, Trible said.

The 80-to-18 vote to retain the tax on foreign investment in real estate marked the first time that the Senate passed a substantive change in the Finance Committee's bill. Asserting that the change did not affect the measure's basic outlines, Packwood and other committee members switched their votes to join the majority after realizing they were beaten.

The defeat for Packwood did not appear to signal that the tax package was unraveling. The amendment at stake, proposed by Sen. Howard M. Metzenbaum (D-Ohio), exchanged the $1.2 billion in tax relief for foreign real estate investors with provisions allowing farmers to use income-averaging and providing more generous medical deductions for all taxpayers than the committee's bill proposed.

The committee measure would repeal income-averaging generally and allow medical deductions only for expenses exceeding 10 percent of income. The Metzenbaum proposal drew a broad coalition of senators from Farm Belt states and others who were concerned about cutting the medical deduction. Sen. David F. Durenberger (R-Minn.) said he did not foresee another issue generating such a wide swath of supporters. He also said that a majority of the committee's members opposed repeal of the foreign investors' tax from the outset. He said it was included in the bill largely to win the support of Sen. Malcolm Wallop (R-Wyo.).

Wallop, who defended the provision on the Senate floor, said it had been passed at a time of escalating farm prices but that now, with prices falling, it had become an "impediment" to foreign investment.

"When the farmer who's going bankrupt puts his property on the market, he's going to wonder . . . why this Senate has diminished his marketplace," an angry Wallop said after the vote. "I want to thank those members of the Finance Committee and others who said they'd hang with us for not doing so."

Resuming its stand against amendments in its final vote last night, the Senate defeated, 65 to 29, an amendment by Sen. David H. Pryor (D-Ark.) to repeal a special benefit granting $500 million in tax relief over five years to faltering steel companies. Senators informally agreed, however, to require steel companies to use their tax savings to invest in steel rather than to acquire other ventures.

Before the vote, Pryor waved home-state newspapers that were reporting layoffs in numerous industries. "Is there anything in this bill to help those people?" he asked. "The answer is no."

The committee bill would reduce the number of tax brackets for individuals from 15 to two, with rates of 15 percent and 27 percent; eliminate or limit many deductions, and take 6 million low-income taxpayers off the tax rolls.

Earlier, the Senate rejected efforts to remove from the bill a so-called "transition rule" that would benefit Cimarron Coal, a limited partnership with Colorado investors. The rule would let the partners pay low capital gains taxes on royalty income from their coal mine's contract with a southwestern Colorado utility. The bill would otherwise repeal the favorable rate for capital gains, which would be taxed as salary income