The Reagan administration staved off a potentially embarrassing foreign policy setback yesterday when the House narrowly defeated a bill to repeal economic sanctions against the Soviet Union's natural gas pipeline to Western Europe.

The 206-to-203 vote, however, was indicative of widespread congressional dissatisfaction about sanctions imposed by President Reagan after imposition of martial law in Poland. The sanctions forbid export of equipment for the pipeline by U.S. companies or European companies using U.S. technology.

The timing of the vote contributed in part to its defeat. Secretary of State George P. Shultz is engaged in delicate negotiations in New York City this week with foreign ministers of Western European countries that have defied the sanctions.

In a splintering of Republican unity, House GOP leader Robert H. Michel, whose Peoria, Ill., district has been hurt by the export embargo, led the fight to repeal the sanctions.

Equally unusual was the fact that the Democratic leader, Speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.) relayed in a speech Shultz's argument that the bill would embarrass the administration.

Michel's bill, which would have lifted the sanctions, was replaced on the 206-to-203 vote by a substitute sponsored by William S. Broomfield (Mich.), ranking Republican on the Foreign Affairs Committee.

Broomfield's bill cancels the sanctions after 90 days, "providing the president certifies to Congress that the Soviet Union is not employing . . . forced labor" in constructing the pipeline.

Since Reagan is unlikely to be able to make such certification, the Broomfield substitute effectively leaves the sanctions in place. The substitute was described as "very clever" by Silvio O. Conte (R-Mass.), who supported repeal.

"Who's for slave labor during an election campaign?" Jonathan B. Bingham (D-N.Y.) asked. Members felt that, if they voted against the "artfully contrived" substitute, "they'd be voting in favor of slave labor," he said.

Foreign Affairs Committee Democrats who had voted for repeal portrayed the issue as a question of jobs, claiming that the sanctions have thrown thousands of Americans out of work and have denied U.S. companies lucrative contracts.

O'Neill clearly distanced himself from the committee when he took the floor at the end of the debate to say Shultz had called him over the weekend and said he was "bitterly opposed" to the bill. O'Neill said Shultz told him that the bill would send Shultz to meetings with European and Soviet diplomats "without any cards" and cause an "embarrassing situation."

Samuel S. Stratton (D-N.Y.) said, "The Speaker killed the thing by talking about Secretary Shultz. This is a jobs bill. The Democrats ought to be in favor of that at a time when the economy is in trouble."

Stratton said 1,300 persons in his district have been thrown out of work because General Electric Co. cannot fulfill a turbine contract.

Maryland Democrats Michael D. Barnes and Steny Hoyer voted against the Broomfield substitute, while Virginia Republicans Stanford E. Parris and Frank S. Wolf voted in favor of it.

Lobbying by White House and State Department officials against the bill was heavy. However, the case favoring repeal was made largely by midwestern Republicans during an hour of lively debate.

"This is a parochial interest for me," said Michel, who faces a tough election race in a district with an unemployment rate of 16 percent. "The domestic impact of the sanctions hits hardest in central Illinois."

Michel and his cosponsors argued that the pipeline is being built despite sanctions and that it is inconsistent to lift the grain embargo, as Reagan did and then impose economic sanctions that cause friction with European allies.

Opponents countered that the pipeline will provide the Soviets hard currency and that by supporting it, the United States is propping up a weak Soviet economy and abandoning the Polish people.

Dick Cheney (R-Wyo.) said the Broomfield substitute gave "everybody the opportunity to save face. We're uncomfortable with the sanctions, but we did not pull the rug out from under Shultz. We sort of muddied the waters."