The Senate Finance Committee approved legislation yesterday that for the first time would require foreigners who buy and sell real estate in the United States to pay taxes on the profits they make from such sales.

The move was designed to assuage American farmers, who have complained that the tax exemption now allowed foreigners on such transactions permits them to bid up U.S. land prices and gives them an unfair advantage.

The committee also approved two dozen narrow-interest tax breaks benefitting specific individuals or corporations, as part of a last-ditch effort to push these measures through before Congress adjourns later this month.

However, in the face of outside pressure, panel members withdrew several more controversial narrow-in-terest proposals, including those that would have aided the E. F. Hutton securities firm, silver commodities investors and owners of vacation homes.

In an unusual rebuff, committee Chairman Russell B. Long (D-La.) said flatly he had had enough of the Hutton amendment, which was rejected last year by a House-Senate conference committee, and would "just like to say goodbye."

The Carter administration had opposed each of these narrow-interest provisions as little more than private relief for individual compaines or groups. Most of those that passed were relatively minor.

The committee also rejected, at the urging of the Treasury, a conservative-backed proposal that would have reversed a 1978 crackdown on abuses in certain kinds of company-run health insurance plans.

It also approved a provision by Sen. Lloyd Bentsen (D-Tex.) that would eliminate the present requirement that a 30 percent withholding tax be imposed on payments to foreign investors that are targeted to foreign capital markets.

And it scaled back a proposal to widen the exclusion now granted to charity workers who are employed overseas. The committee approved the extra tax relief only for those who are stationed in less-developed countries.

Despite yesterday's marathon voting session, it's not at all certain that the bill affecting foreigners' profits from U.S. real estate transactions will pass both houses this session.

The House Ways and Means Committee considered a similar measure last Wednesday, but defereed it indefinitely because of panel members' objections to various portions of the bill.

Nevertheless, the measure was chosen as a vehicle for the narrow-interest amendments by the Finance Committee because it would raise $75 million in new revenues, enabling the panel to cut taxes elsewhere without busting the budget targets.

Congressional staffers estimated the narrow-interest provisions that the panel approved yesterday would total about $74 million. The most expensive of these was the Bentsen amendment, which cost $25 billion a year.

For all its reluctance to approve some of the more controversial narrow-interest provisions, the committee did send to the floor a spate of lesser proposals in the category, some of which may be challenged during floor debate.

Among the beneficiaries would be the Hormel Foundation, the railroad industry, owners of private wood lots, Alaskan Indians, the estate of a Tennessee woman and makers of fishing tackle.

The Hutton amendment, rejected last year by a House-Senate conference committee, would have allowed a tax exemption for several billion dollars' worth of industrial revenue bonds that were caught in an Internal Revenue squeeze in 1978.

Although the Carter administration had served notice that summer it would cut off the tax exemption for early refunding of such bonds, Hutton and other firms continued to market them. However, the IRS issued its ruling early, catching them in a bind.

The proposal involving commodities trading would have reversed a 1977 IRS ruling that prevents buyers of silver futures from creating short-term losses to avoid tax on long-term gains -- a lucrative tax shelter in the past few years.

The measure the panel approved granting relief to the railroad industry would, in effect, protect railroads from an expected Interstate Commerce Commission ruling tightening the methods by which they write off expenses for railroad ties.