Congress voted final approval for huge new Social Security taxes yesterday and adjourned until Jan. 19, but only after an unexpectedly close vote on the Social Security bill in the House.

Republicans and some Democrats in both chambers turned on the Social Security compromise, attacking it as too expensive and too costly to middle-class Americans. The bill - which will raise payroll taxes by $227 billion during the next decade - finally passed the Senate 56 to 21, and the House by 189 to 163.

But an earlier tally in the House authorizing floor debate on the bill passed by only three votes. Had it failed, there would have been no Social Security legislation this year.

Congress adjourned without making any new progress on President Carter's energy program, which had been his top priority in this now-ended session. A small group of House and Senate conferees met informally yesterday to discuss the sticky question of natural gas price controls, but found no new formula to break their longstanding deadlock.

Rep. Harley O. Staggers, chairman of the conference on nontax aspects of the energy program, asked the senators and representatives in that conference to stay in Washington next week and be ready to resume deliberations. It was unclear how many would actually do this.

In other action on their last day in session, the House and Senate approved a compromise clean water bill that somewhat loosens federal controls on water pollution but generally extends the 1972 Clean Water Act.

Some environmentalists have attacked the compromise bill as too lenient. Dealines for industry to clean up discharges into waterways and lakes were extended somewhat in the bill, and government water projects were exempted from some clean water requirements.

The compromise passed the Senate by voice vote, and the House with only two dissents - Reps. Elizabeth Holtzman and Ted Weiss, both New York City Democrats. Holtzman said later she thought the government had an obligation to be as strict as possible in cleaning up the country's water.

Another voice vote in the Senate sent to the President a new legal services act extending the fedrally financed legal services program for poor people for three years, but precluding its lawyers from entering school desegregation cases. The House had already approved the measure.

The Senate also voted to extend until Feb. 15 the federal government's emergency powers to allocate natural gas supplies in the event of shortages like last winter's. But this extension was blocked in the House by members who said it should be part of a new energy package. They apparently felt this allocation provision made the entire energy package more attractive, so should be saved as a means of helping the whole package win approval.

The Senate ducked a key vote on the B-1 bomber, apparently because pro-administration senators trying to support President Carter's cancellation of the B-1 weren't sure they could win the vote.

The Senate will vote in January on an appropriation to build two more prototype B-1's, despite Carter's cancellation of the bomber program. The House has thus far approved these two additional prototypes, and a coalition of senators who favor either B-1 production or retention of the option to produce the high-speed, low-altitude bomber hope to keep this money in a supplemental appropriations bill.

The Carter administration says it would be a waste of money to build these two planes. Administration allies in the Senate claim they have a majority of votes to knock the money out of the appropriations bill, but apparently these allies weren't sure they had the votes yesterday afternoon.

About a fourth of the Senate was absent yesterday, and some of those on hand for the midday vote on Social Security had begun to leave town by mid-afternoon.

In the debate on the Social Security compromise, many Republicans appeared to decide that their interests would be best served if they spoke against the enormous tax increases that every working American will begin to feel in 1979, and go on feeling with increasing intensity for the rest of the century.

Sen. Barry Goldwater (R-Ariz.) said the size of the tax increases in the bill only proved that Social Security had failed, and he said the system should now be abolished, returning every citizen's share of the money. But most of the others who spoke against the compromise attacked the schedule of new taxes, not the entire program.

Sen. Carl Curtis (R-Neb.), for example, said the new taxes will "soak the middle class." Rep. Barber B. Conable Jr. (R-N.Y.) called the measure "the biggest peacetime tax increase in history," and predicted it would cause more unemployment.

But Senate Finance Committee Chairman Russell B. Long (D-La.) called it a reasonable bill, and Rep. Al Ullman (D-Ore), chairman of the House Ways and Means Committee, said "a 'no' vote is a vote for insolvency of Social Security funds."

The Carter administration was forced to propose new Social Security taxes because the existing level of employer and employee contributions to the funds would soon prove insufficient to cover obligations to disabled, sick and elderly Americans.

The administration proposed making a contribution to the Social Security funds from general Treasury revenues, but neither House would subscribe to that idea. The final compromise calls for a more progressive payroll tax that will raise the lowest-paid worker's contributions by about 15 per cent between 1979 and 1987. Highly paid workers will end up paying about three times the amount of payroll tax that they now pay.

Employees and employers will continue to make equal contributions to Social Security under the compromise.

In years past, the last days of congressional sessions have often proven to be wild affairs, lasting long into the night and punctuated by unusual parliamentary devices and developments. But this year Speaker Thomas P. (Tip) O'Neill Jr. in the House and Senate Majority Leader Robert C. Byrd both managed orderly, calm sessions that ended in time for everyone to get home for supper.