The Moscow-supported Afghan government of Babrak Karmal and Pakistan have agreed to pursue talks with U.N. officials on the Soviet military occupation of Afghanistan, indicating a receptiveness by both governments to U.N. efforts to negotiate a political solution, according to diplomatic sources.

In talks with U.N. special emissary Javier Perez de Cuellar this month, Gen. Mohammed Zia ul-Haq of Pakistan and the Babrak government in Kabul continued to refuse to engage in face-to-face negotiations over the withdrawal of Soviet troops from Afghanistan. However, diplomatic sources said that the two governments agreed to have their foreign ministers meet separately next month with U.N. Secretary General Kurt Waldheim.

A great deal more work needs to be done on the U.N. initiative, diplomats said. According to the sources, however, both Afghanistan and Pakistan have agreed that the United Nations should press forward, and Kabul's compliance indicates that the Soviet Union is leaving open the possibility of a U.N.-negotiated solution.

"Both sides are showing some flexibility," said one diplomatic source with knowledge of the U.N. effort. "The encouraging thing is that the two sides, for almost opposite reasons, remain interested in this process."

The U.N. mediation efforts have centered on a four-point agenda, repeatedly endorsed by Pakistan, that includes the withdrawal of Soviet troops from the war-torn country, noninterference by other outside parties, guarantees of Afghanistan's independence and the return of refugees.

One of the largest difficulties now facing the U.N. initiative is Pakistan's continued unwillingness to engage in direct negotiations with the Kabul government without the participation of Iran, which also borders Afghanistan. Iran's government has said it will not participate in any negotiations until Soviet troops withdraw from Afghanistan.

The Soviets and the Babrak government they back, in contrast, have consistently maintained that formal negotiations on withdrawal of the Soviet forces cannot proceed until foreign support for the insurgents fighting the current government -- which they maintain has come from the United States and other powers as well as Pakistan -- ceases.

Cuellar, a Peruvian diplomat and former U.N. undersecretary who was appointed by Waldheim to conduct negotiations as his personal emissary, visited Kabul and talked with Zia in Karachi before returning to New York this week. He was unable to meet with the Islamic rulers of Iran, who are said by diplomatic sources to be preoccupied with internal turmoil and currently cool to the U.N. mission.

It is understood that Zia has agreed to try and persuade Tehran to relax its stand.

If, however, the Iranians stand firm, it is possible that this problem could be evaded by leaving an empty chair at the negotiating table that the Iranians could fill at a later date, sources said.

If direct negotiations are arranged, neither the United States nor the Soviet Union would be invited but they, the Chinese and the Indians would be well briefed throughout and there is a possibility of observer status.

De Cuellar is working on a 10-page report for Waldheim, which will form the basis of a major speech to the General Assembly next month.

The speech could be designed to head off another U.N. General Assembly condemnation of the Soviet presence in Afghanistan. The Secretariat fears that such a condemnation would restrict its maneuverability in future negotiations.

British sources said that a European Community initiative is still on the table and the British foreign secretary, Lord Carrington, expects to discuss it with Soviet Foreign Minister Andrei Gromyko when the two meet in New York next month. But other sources said the Common Market plan is dead, but it served a useful purpose in making the U.N. proposals look more attractive to the Soviets.