President Najib accused Pakistan on Saturday of massing troops along the border in preparation for an invasion and eventual annexation of Afghanistan.

The government also released 20 imprisoned Iranians to improve relations with its western neighbor, but an Iranian diplomat said his country will not be satisfied until Moslem guerrillas win the civil war.In a nationally broadcast speech, Najib said his government had received information Pakistan planned first to attack Jalalabad, about 80 miles east of Kabul and 50 miles west of the Pakistan border.

"Militarist and reactionary parties envisage swallowing our country and turning it into a fifth province of Pakistan," the president said. Pakistan has allowed Moslem guerrillas fighting Najib's Soviet-backed government to operate from Pakistan.

Pakistan, the United States and Iran have supported the guerrillas, who began fighting in 1978 after the communists took power in a coup. In 1979, the Soviets sent troops into Afghanistan to prop up the pro-Marxist government.

Under a U.N.-mediated accord, all Soviet troops must be withdrawn by Wednesday. Radio Moscow reported Saturday the last motorized army unit was within 125 miles of the Soviet border.

Afghan Foreign Ministry spokesman Mohammad Nabi Manai said 20 Iranian prisoners were freed to commemorate the 10th anniversary of the Iranian.

The prisoners appeared to be in good health, but many showed reporters scars and missing teeth and said they had been repeatedly beaten and tortured.

With the withdrawal deadline approaching, Najib exhorted the Afghan people to protect their nation's sovereignty. "Say in one voice: `Country or death,' " he said.

In Islamabad, Pakistan, there appeared to be no end to the dispute among guerrilla factions over the composition of a provisional Islamic government they want to form. At issue is how power would be shared by the seven insurgent groups in Pakistan and the eight in Iran.

Radio Moscow said patrols along the Salang Highway, the main route between Kabul and the Soviet border, were being discontinued.

According to the report, the last motorized Soviet unit traveled through a mountain pass on the Salang Highway. It did not say how many troops or what kind of equipment were in the unit.

The report also said a "small group" of soldiers will remain in Kabul, the Afghan capital, to guard the airport until the Soviets complete a massive food airlift. Col. Pavel Vinokunov said the airlift will continue until Monday and his men will depart then.

Six hundred trucks bearing vital food and fuel for the capital rolled into Kabul Saturday. The trucks completed the four-day trek from the Soviet border shortly after a convoy of Soviet troops crossed through the Salang mountain pass heading in the opposite direction.

Col. Gen. Mikhail Moiseyev, the military chief of staff, has said the last Soviet soldier will leave Afghanistan on Tuesday. Soviet officials have said the Red Army contingent in Afghanistan numbered 115,000 before the pullout began May 15 and that half had left by Aug. 15.