Pakistani President Zia ul-Haq appealed to President Carter yesterday to keep the United States out of the war between Iraq and Iran, saying that any involvement by superpowers will only make the 12-day-old conflict in the Persian Gulf more difficult to solve.

Zia, recently returned from visiting Baghdad and Tehran on an unsuccessful peace mission launched by Islamic states, expressed pessimism that the war will be over soon.

At the same time, he said, both countries have only limited supplies of spare parts and other essential war material, and thus in his opinion as a professional military officer the conflict will be limited in its intensity.

In a 75-minute White House visit, most of it a private meeting of the two presidents without advisers, Zia gave Carter a first-hand account of the military objectives and political posture of the Persian Gulf combatants. Zia reiterated his views later in a talk with reporters.

The White House meeting, the first face-to-face encounter of Carter and Zia, was also the occasion for clearing the air to make way for a new start in troubled U.S.-Pakistan relations. Early this year Zia scornfully rejected as "peanuts" Carter's offer of $400 million in U.S. economic and military assistance following the Soviet invasion of Afghanstan.

Until that invasion, the overriding issue in U.S.-Pakistan relations was the belief here that Pakistan was engaged in a program to produce its own nuclear bomb. U.S. aid to Pakistan was cut off twice in the last three years because of activities that violated Americans laws or policies aimed at halting the proliferation of nuclear weapons.

Zia told reporters yesterday that the recent decision by the Carter administration and the Senate to send a new shipment of nuclear fuel to India, which exploded a nuclear device in 1974 and has refused to place all its atomic facilities under international safeguards, places Pakistan's nuclear efforts "Morally . . . on a higher plane."

Should the United States persist in trying to restrict Pakistan's nuclear program, which Zia insisted is peaceful, "It will be sheer discrimination" in view of the fuel shipment to India, Zia said.

According to Zia, the subject of his country's nuclear efforts was never raised in the White House meeting. This suggested a dramatic downgrading of the nonproliferation issue in Carter's concerns and interests about Pakistan.

Zia, who described his country as "trying its best to be non-aligned and equidistant between America and the Soviet Union," said his principal request of the United States is for economic rather than military assistance. r

White House officials said consideration is being given to new U.S. aid to Afghan refugees who have crossed the border to camps inside Pakistan and that "we are not rigid on sales of military equipment" to Pakistan. However, direct economic aid and military credit sales to Pakistan are barred at present by U.S. nonproliferation laws.

Pakistani Foreign Minister Agha Shahi, who accompanied Zia, said active discussions have been taking place involving Islamic nations, represented by Pakistan, and the Soviet Union about the terms for Soviet withdrawal from Afghanistan.

He said the talks have sought to find a mutually acceptable forum for discussion of the conditions for Soviet withdrawal. So far there is no agreement, but talks continue, he said.

Zia expressed the view that in the Iraq-Iran war, the Soviet Union is seeking to bring an end to the fighting as soon as possible, in view of the complex iterplay of its arms relationship with Iraq and the strategic position of Iran on Russia's southern border.

The Soviets, like the United States, should leave the two combatants alone in order to maximize chances for a settlement, Zia said.