The House gave the Carter administration a key foreign policy victory yesterday by approving controversial legislation implementing the Panama Canal treaties.

After narrowly rejecting a last-ditch effort by conservatives to embarrass the administration by forcing the Panamanians to pay part of the costs of the treaties, the House sent the bill to the Senate on a vote of 224 to 202.

The House action came after a long struggle between conservatives opposed to the treaties and the administration, which undertook an intensive lobbying and publicity campaign that included an endorsement from John Wayne shortly before he died.

House leaders twice pulled the bill off the floor when it appeared that the conservatives had enough votes to pass crippling amendments that might have prompted the Panamanians to repudiate the treaties.

President Carter said yesterday he was pleased with the passage of the bill but said he would work for "improvements" in the Senate. But the chief House sponsor, Rep. John M. Murphy (D-N.Y.), and the principal opponent, Rep. Robert E. Bauman (R-Md.), warned that the House would reject the measure if it were altered significantly in the Senate.

"If the president thinks he can take the bill to the Sentae, strip it and bring it back to the House and pass it, he's sadly mistaken," Bauman said. And Murphy said the House would "send the conference report back to conference" if major House provisions were dropped.

The House provisions require Congress to authorize and appropriate funds annually to be spent in accordance with the treaty for moving U.S. defense facilities and paying retirement benefits and other costs. It also requires that toll money be deposited in the Treasury.

The administration wanted a more automatic release of funds and for the executive branch to oversee the operation of the treaty terms which would basically set up a commission to operate the canal until it is turned over to Panama in 20 years.

Opponents of the treaties tried in the House to cripple the legislation by forcing Panama to pay the costs of the treaties, such as moving U.S. bases out of the canal zone, providing pensions for U.S. employes who lose their jobs and underwriting the costs of property transfers.

Rep. George Hansen (R-Idaho) claimed these amendments would keep the administration "honest" in its assertion that there was no cost to the U.S. taxpayer. But Hansen's amendments failed by a 220-to-200 vote Wednesday night.

Yesterday, however, Hansen's supporters came much closer with an amendment that would have forced Panama to pay about $57 million for moving U.S. military facilities out of the Canal Zone and rebuilding them elsewhere.

The amendment, by Rep. G. V. (Sony) Montogomery (D-Miss.), was rejected 213 to 210, but only after Democratic leaders, yelling "It's son of Hansen," changed enough votes at the last minute to defeat it.

Another amendment adopted by voice vote would halt payments to Panama if the president and Congress determine Panama is interfering in the internal affairs of other countries. The amendment, by Rep. Charles Pashayan Jr. (R-Calif.), is aimed at curbing Panama's support of Sandinista rebels in Nicaragua and rebels in El Salvador, but the administration is likely to press for its removal from the bill in conference.

The bill establishes a Panama Canal Commission under the control of the Defense Department, requires all toll revenues be paid to the Treasury, requires expenditures be made subject to appropriations and provides for payments to Panama as required by the Treaties.

Under the treaty, Panama would get some $75 million annually from toll revenues until the canal is turned over to it in 20 years.

The United States would transfer to Panama free of charge such property as a railroad and housing units. In additions, it would pay for moving U.S. military facilities, pensioning of workers and other costs relating to U.S. employes of U.S. defense forces.

Bauman predicted that support of the bill would cost a few House members their seats, because Americans would perceive it as vote on the Panama Canal treaties themselves

Murphy said it would still be an issue in 1980, but said the vote for the legislation could be defended as a vote to implement what the Senate in 1978 had already approved as the law of the land. CAPTION: Picture, Porters at Managua's Intercontinental Hotel assist an American TV crew load equipment for their departure. AP