The Dec. 27 coup in Afghanistan was a carefully staged Soviet operation in preparation for which Moscow began sending in large numbers of troops a month in advance, according to information gained from a number of sources during a three-day stay in Kabul last week.

It is clear that Moscow's claim to have sent in troops in response to an Afghan request under the Soviet-Afghan friendship treaty blantantly ignores some crucial elements of timing. It also appears clear that Soviet duplicity laid the groundwork for the violent overthrow of the government of president Hafizullah Amin.

The Soviet say Amin was deposed by the new Afghan leadership, but diplomatic sources in Kabul said it was an entirely Soviet force that carried out the coup in assualts on key installations guarded by Afghan forces.

According to well-informed diplomats, the Soviet military buildup that paved the way for the coup started around the beginning of December. Three weeks later, the sources said, Soviet military strength had reached the level of about a brigade at each of three key places: the airbase at Bagram about 50 miles north of Kabul, the airbase of Shendan in the west and the capital itself.

It still was not clear what Soviets' intentions were, diplomats said.

Then, on Dec. 24, the influx suddenly escalated dramatically. For two days and two nights, the Soviet transport planes flew into Kabul airport with almost all elements of an airborne division of 6,000 Soviet combat troops.

"We could hardly sleep," said one Afghan. "The planes just kept coming in low over the city one after the other. The noise rattled the windows and shook the floors."

The airlift coincided with the Christmas holidays and the Iranian hostage crisis was preoccupying the West in general and the United States in particular, diplomats noted.

U.S. estimates now put the number of Soviet troops in Afghanistan at between 30,000 and 40,000.

Attempts to get information about the troop buildup met little success. One senior diplomat met the deputy foreign minister on the morning of the coup.The Afghan official, who has stayed in his position under the new government, never mentioned the Soviet-Afghan friendship treaty as a justification for the Soviet airlift. When asked about the Soviet troops, he simply refused to acknowledge their presence, sources said.

Then, that night at about 7:30, a loud explosion at the telecommunications building knocked out most internal and external telephone and telex facilities. bIt appeared to be the signal for the start of the coup.

Soviet troops immediately attacked the radio and television station next to the U.S. Embassy, the People's House presidential palace and Duraluman Palace where Amin had just set up residence.

At the time of the coup, Soviet forces massed on their side of the border came pouring across in a three-pronged invasion. One column crossed the border at Torghundi and seized the provincial city of Herat. Another swept across and took Mazari-Shariff, and the third came down the Kunduz Valley north of Kabul.

"The coup was entirely carried out by Soviet troops from A to Z," one diplomat said.

Ironically, the sources said, Soviet advisers had told Amin to move from the People's House in Kabul to the palace for his safety. Durulaman Palace sits at the end of a long dead end access road a few miles out of the city near the Soviet Embassy.

The Soviet strike force, spearheaded by light tanks that had been airlifted in, was comprised of no more than two or three battalions sources said. By most accounts, it encountered unusually stiff resistance from Afghan troops guarding the building.

Casualties on both sides were considerable, sources said. One figure mentioned is roughly 25 Soviets killed and 225 wounded, with substantially higher tolls on the Afghan side.

While the fighting was still going on, an odd thing happened that may have meant a wrinkle in the Soviet planning.

At 8:30 p.m. Kabul time, a senior diplomatic envoy said, he was listening to Radio Moscow and heard a taped speech by Babrak Karmal announcing the ouster of Amin and his own accession to power.

The fighting in Kabul to depose Amin did not end until about 11 p.m. local time, however, and the speech by Karmal was only broadcast on Radio Afghanistan sometime afterward. Residents of Kabul are sure the announcement was taped -- it was repeated later in the same words and tone -- and that Karmal was not yet in the country.

Sources said he flew in the next day on a Soviet transport plane from Moscow. He reportedly went to the Soviet capital shortly before the coup after living in exile in Prague, where he had served briefly as the Afghan ambassador until resigning to avoid a purge by Amin.

In any case, Karmal was not seen locally until the night of Jan. 1, when he made a speech on television.

Exactly what happened to Amin remains shrouded in some mystery. One account has it that he and a number of guests at Durulaman Palace were gassed to sleep where watching a film and that he and several aides were then taken off to be executed.

That does not explain the fighting at the palace, however, More likely is a version that says Soviet tanks and troops simply blasted away crudely at a building in which he was staying adjacent to the palace, killing him along with members of his family.

The building was practically demolished in the fighting and witnesses said it burned for 24 hours.

In addition to the whereabouts of Karmal, other aspects of the operation pointing to Soviet installation of handpicked government officials include the case of four men who had sought refugee in the Soviet Embassy in Kabul months earlier to avoid arrest by Amin.

All four were then flown to Moscow and suddenly reappeared as government ministers and revolutionary council members after the coup.

In addition, a military officer, Maj. Gen. Abdul Qader and two other officials who were purged and jailed under the previous government, were announced as being in the Cabinet on the morning after the coup. They reportedly had been spirited away from jail shortly before.

What exactly triggered the Soviet decision to move against Amin remains debatable. Diplomats say that it was probably a series of events rather than a single deed.

The Soviets are believed to have tried to get rid of the brutal and unpopular strongman in September, but the attempt backfired and Amin, then prime minister, took over from president Nur Mohammed Taraki in a coup.

Thereafter the Soviets grew increasingly disenchanted with Amin, who one diplomat said had become "unmanageable."

Amin in turn was apparently becoming more and more suspicious of the Soviets.

Then, about 10 days before the coup, a relative of Amin's in charge of the secret police was shot in the chest by assassins and flown to Moscow for emergency treatment. He is said to have died on the plane. Some diplomats believe that the Soviets may have used this incident to persuade Amin to build Soviet strength in Afghanistan.

The Soviets have been the target of violence as well, including one incident shortly before the coup in which three Soviet advisers were stabbed to death in the Kabul bazaar.

Diplomats believe the Soviets must also have realized that the government in Kabul might not survive another spring offensive by the rebels such as the one staged last year. The Soviets presumably reasoned it was better to move against the insurgents during the cold, snowy winter when their mobility is limited and their mountain redoubts are inhospitable.