The International Association of Machinists, the nation's fifth-largest union, announced yesterday that it will give no campaign aid this year to any congressional candidate who votes for the natural gas compromise, and is withdrawing support from several liberals who recently switched and backed the bill.

It was an extraordinary step. Unions and other interest groups rarely refuse aid to friendly lawmakers on the basis of a single vote. But Machinists President William W. Winpisinger said this bill, which would allow the price of natural gas to rise substantially between now and 1985, is that important.

Winpisinger also told a news conference the IAM leadership has "written off" President Carter for "caving in" on several issues important to labor and will look for another presidential candidate in 1980 or "maybe sit it out." He released copies of letters sent to Carter and every member of Congress informing them of the IAM decision.

One immediate effect of Winpisinger's announcement was to withdraw a campaign staff assistant from Sen. Dick Clark (D-Iowa), whom the IAM had given $10,000 before he voted last week against an attempt to scuttle the bill ending price controls on new natural gas by 1985. Machinists' aid will also be withheld from Sen. William Hathaway (D-Maine) for voting with Clark. The money will be added on to contributions to candidates who vote right, said Winisinger.

Winisinger, who concedes he often is a lonely liberal voice in AFL-CIO leadership councils, said he had not asked other unions to join his boycott and does not intend to.

The million-member Machinists have a campaign war chest of $600,000.

Rep. Philip R. Sharp (D-Ind.), chairman of a task force trying to line up House votes to pass the gas bill, said some members who have been supported by the Machinists in the past had advance warning of Winpisinger's decision to cut off campaign funds. Sharp said he thought not all local union members would withhold their votes from friendly Congress members for what their leadership considered one had vote.

Winpisinger told reporters: "There is a time for pragmatism and a time for principle . . . and of today, the Machinists Union has taken a stand on principle . . . we are fed up with posturing politicians who come around, seek our support, our money, our votes and then when the critical issues are up for a vote they see fit to horsetrade and swap votes on the issue."

Winpisinger said his union will not support those who vote for the gas bill but will not actively oppose former friends.

IAM considers this the most important consumer vote that the 95th Congress will cast, the union leader said. He traced the Carter position from his April, 1977 proposal to continue regulation, through his declarations that deregulation would cost consumers up to $70 billion more by 1985, to enthusiastic support of the present phased deregulation compromise. He also faulted Carter for not fighting hard enough for national health insurance, full employment and labor law revision and doing too little to combat inflation.

"Everything for the people is down the drain," said Winpisinger. "We will no longer pay for votes against us."

The president's apparent Camp David success in setting Israel and Egypt on a road to peace can't make up for his domestic failings, Winpisinger said. "I don't think one foreign policy spectacular will turn things around for Carter."

The Senate is expected to approve the natural gas settlement tomorrow. A House vote is not expected until about Oct. 12, two days before Congress hopes to adjourn for the year.

If the Senate approves the gas bill, the House-Senate conference on non-tax parts of Carter's energy bill will be reconvened to agree to drop a Senate provision banning sale of big inefficient cars. Then the schedule calls for the Senate to pass two lesser energy bills dealing with electric utility rate structures and an omnibus conservation bill.

The House would bundle these three plus a coal conversion bill into one package for one up or down vote. It is conceivable that Senate gas-bill opponents may try to slow the process by filibustering against the utility and conservation bill, or that a snag may arise when the House takes up a rule to package the four together. Opponents of the gas bill want to put it to a separate vote.

Finally, the energy tax conferences - who haven't held a working session since last Thanksgiving - are expected to meet again. The top-priority domestic crude oil tax is dead, but they may salvage tax credits for home insulation and a tax on sales of gas-guzzling cars.