The House passed its first foreign aid appropriation bill since 1979 yesterday as enough Republicans rallied around President Reagan to save his administration from an embarrassing defeat.

The $11.4 billion package, including new military assistance funds for Middle East countries, passed 199 to 166. Eighty-four Republicans backed it, but only after the heaviest party pressure was applied to overcome their traditional reluctance to support foreign aid. Eighty-seven Republicans voted against it.

A three-hour debate punctuated by shouting matches among Republican members produced the final agreement on a carefully balanced bill whose fate was temporarily in doubt. Only fervent appeals to support their president induced many Republicans to swallow their opposition to sections offering loans to undeveloped countries.

It was a victory for Rep. Clarence D. Long (D-Md.), chairman of the Appropriations subcommittee on foreign operations, and Rep. Jack Kemp (R-N.Y.), who patched together a compromise that took enough steam out of the GOP opposition to achieve a majority.

Since 1979, support for foreign aid has been so thin that no bill has been brought to the House floor and the programs have been governed by continuing resolutions.

If the same rule had been followed this year, the appropriation would have been $9.7 billion, and Reagan would have been forced to do without $300 million in military credits he has proposed for several Middle Eastern countries.

The major clash was over an appropriation of $850 million for the International Development Association (IDA), which makes long-term, non-interest-bearing loans to some of the world's poorest countries.

Conservative Republicans led by Rep. Mickey Edwards (R-Okla.) tried to cut it back to $520 million, contending that the United States was in part financing unfriendly countries.

"Why subsidize this country's enemies?" asked Edwards, singling out India, which got 40 percent of IDA loans last year, as a country that frequently criticizes the United States and gets arms aid from the Soviet Union.

Had the IDA appropriation been cut that much, a band of liberal Democrats was prepared to vote against the bill because of its emphasis on new military aid. Their opposition would have killed it.

Kemp, declaring that "our president" needed the bill, countered with an amendment trimming IDA to $725 million. He, too, expressed reservations about IDA, but said, "This is the best we can get."

Democrats looked on in amusement as the Republicans fought it out. Edwards denounced Kemp for offering only a "cosmetic cut" in IDA, and Kemp and Rep. John H. Rousselot (R-Calif.) traded insults for several minutes over the concept of multilateral aid contributions.

Reagan, although critical in the past of multilateral aid organizations not controlled by the United States, had endorsed a full $850 million funding for IDA, and loyalty to him became the principal issue.

"This is a Reagan vote," Rep. Sylvio O. Conte (R-Mass.) warned the conservatives, who keep careful tabs on who votes for and against the president. "So you'd better take your little report cards out and check this one."

Kemp's amendment passed 282 to 113, ending most of the day's debate. To avoid a tough amendment to cut back the amount of funds that could be loaned to India, Kemp also offered successfully another substitute which merely instructs the administration to get IDA to reevaluate the distribution of its loans.

The bill must now be reconciled with an $11.6 billion bill passed earlier by the Senate. Although the two measures contain nearly identical spending totals, there are substantial differences on individual programs.

The House bill includes $1.53 billion for multilateral aid, $4.98 billion for bilateral aid, $900 million for military assistance, and $3.97 billion in borrowing authority for the Export-Import Bank.

All Maryland representatives voted for the bill on final passage except Reps. Marjorie S. Holt (R), Beverly B. Byron (D) and Roy Dyson (D).

Three Virginia congressmen--Republicans Thomas J. Bliley Jr., M. Caldwell Butler and Frank R. Wolf--voted for the bill. All others voted against it except G. William Whitehurst (R), who did not vote.