In a victory for President Carter, the House Commerce Committee approved his hospital cost-containment bill by a 23-to-19 vote yesterday after a day of wrangling on amendments.

The bill's sponsor, Rep. Henry Waxman (D-Calif.), smiled broadly and happily received handshakes and congratulations from fellow Democrats as the call of the roll was finished.

"I think it can get the votes, both Democratic and Republican on the floor and will work to hold down hospital costs," Waxman said after the vote.

Secretary of Health, Education and Welfare Patricia Roberts Harris called the bill "the most significant piece of anti-inflation legislation we've seen for a long time" and said it could bring progress toward a national health plan as well.

The bill -- one of Carter's top legislative requests -- is designed to clamp a lid on the growth of hospital costs, which have far outstripped the general rate of inflation in recent years.

Under the bill, if hospital costs nationwide grow more than 11.6 percent in 1979, mandatory federal controls on hospital revenues will be imposed, based on rises in hospital wage scales, increases in the cost of a "market basket" of hospital goods, and various other factors. If a hospital receives revenues in excess of its mandatory limit, it will be subject to a penalty of 150 percent of the excess.

The bill is estimated by the Department of Health, Education and Welfare to save hospital users about $40 billion over the period 1980 to 1984.

Yesterday's 23-to-19 vote will allow the proposal to go to the House floor with the joint backing of Commerce and the Ways and Means Committee, which also has jurisdiction and has approved a slightly different version estimated to save $31 billion.

Waxman and others said the bill is a combination of voluntary and mandatory controls. The hospitals have a chance to meet the inflation control goal by methods of their own. Only when they don't stay under the cost-rise lid (11.6 percent for 1979 but recomputed each year thereafter) would the mandatory federal revenue controls be imposed.

Before the final vote, the committee approved, 21 to 20, a proposal by Thomas J. Broyhill (R-N.C.), which Waxman and administration spokesmen said would weaken the bill. It allows either chamber of Congress each year to veto the imposition of mandatory controls for the next year even if the voluntary lid has been exceeded.

Waxman charged that a one-house veto would make it too easy for mandatory controls to be knocked out through lobbying by hospitals, and various other health groups, most of which violently oppose the bill as likely to smother hospitals in tons of regulations and block improvement of services. The veto, he said, would undermine the threat of a mandatory lid.

However, Broyhill said he believed Congress would act responsibly, and a later attempt to uproot the provision from the bill failed on a 20-to 20 tie. The one-house veto is also in the Ways and Means bill, but not in a Senate Labor Committee version.

Another Carter-opposed provision, which would have raised the voluntary lid for 1979 to 12.6 percent and thereby made it harder to impose mandatory revenue controls, was killed, 22 to 19, after initially passing 21 to 20.

Richard C. Shelby (D-Tex.) said the extra margin of cost increases was needed to allow hospitals in poor southern communities to improve their quality with special heart, surgical and other serives.

But Waxman and HEW officials said this 1 percent easing of the trigger could reduce the $40 billion saving by up to $12 billion.

Rep. Mickey Leland (D-Tex.), who had first voted for the 1 percent easing in the trigger, switched and helped knock out the increase by forcing a second vote.

Although the cost-containment bill has won approval from Commerce, Ways and Means and Senate Labor, it still faces a tremendous fight on the House floor. It is likely to be considered under an open rule, allowing unlimited amendments.

Spokesmen for the Federation of American Hospitals (1,000 privately owned hospitals), the American Hospital Association, American Medical Association and other medical groups are massed against the bill, on grounds it would downgrade quality improvements with oppressive government regulations. They will go all out to kill it on the House floor. If it does clear the House, its Senate prospects may be good. The Senate passed it in the wanting days of the last Congress; it never passed the House and died with adjournment.