Soviet troops evacuated towns south of Kabul Tuesday in their second major retreat from Afghan outposts, leaving government forces to ward off rebel attacks in the strategic area, Western and Soviet diplomatic sources said.

Soviet troops left Ghazni, 85 miles southwest of Kabul, and were heading north toward the Soviet border, said the sources, who spoke on condition of anonymity.A Soviet convoy from Ghazni reached the outskirts of Kabul about sunrise Tuesday and passed around the edge of the capital, the Western source said. It was not known how many troops were involved.

The Western source said the Soviets Tuesday were also pulling out of Gardez, 60 miles south of Kabul.

The evacuation of Soviet troops from the area leaves the Afghan army largely unassisted, at least on the ground, against attacks by anti-government guerrillas in the provinces separating Kabul from the Pakistani border to the south and southeast.

The guerrillas, who have been fighting both Afghan and Soviet troops, have headquarters in Pakistan, which serves as their conduit for arms supplies by Pakistan, the United States and China.

The Soviet withdrawal started May 15 with departure of troops from Jalalabad, 75 miles east of Kabul.

Under an April agreement signed in Geneva, the Soviets are to complete withdrawal by Feb. 15, 1989. When the pullout began, the Soviets had an estimated 115,000 soldiers in Afghanistan. About 10,000 have left so far, according to reports from Moscow.

The Soviet military intervention in Afghanistan started in Dec. 1979 when troops were dispatched to prop up a Soviet-style government in the face of escalating guerrilla attacks.

Meanwhile, the guerrillas claimed from their headquarters in Pakistan that they had captured the strategic Panjsheer Valley northeast of Kabul last Thursday.

The claim could not be verified in Kabul. Afghan and Soviet officials declined to comment.

The guerrillas claimed Afghan and Soviet troops had left the valley and said they controlled the towns of Rokhah and Anawa.