The morning after the Soviet invasion of Afghanistan late last December, President Carter telephoned Pakistan's president Mohammed Zia ulHaq to offer U.S. aid to draw a line against the Russians at the Afghan-Pakistani border. Zia was surprised, and surprisingly cool.

In the days and weeks that followed. Carter twice announced a high-priority program of aid to Pakistan in nationally televised addresses. National security affairs adviser Zbigniew Brzezinski reaffirmed on TV a 20-year-old U.S. commitment to defend Pakistan. And the Carter administration officially offered Pakistan $400 million in economic and military assistance.

In Isamabad, Zia publicly scorned the U.S. aid as "peanuts" and privately told Washington he wasn't interested in military assistance on such a scale. After turning back a proposed visit by Deputy Secretary of State Warren Christopher, Zia accepted a highly publicized sojourn a month later by Brzezinski and Christopher, during which he told them to proceed no further with U.S. aid without his approval. It has never come.

The spectacle of a poor, weak and threatened nation rejecting U.S. aid and alliance against the Russians in a time of trial was a shock to many Americans. The main elements of how and why this happened, according to U.S. and Pakistani sources, are fairly clear:

First, the Washington policy shift was too sharp, too fast, and without enough preparation.

In August 1977, the Carter administration cut off aid to Pakistan because it was purchasing a nuclear reprocessing plant capable of making atomic bomb material. In September 1978, the purchase deal (with the French) was squashed and aid to Pakistan restored. In April 1979, U.S. aid was cut off again because Pakistan was building its own uranium enrichment plant capable of making atomic bomb material.

Last October, two months before the Soviet invasion, Washington officials pressured Pakistan's senior foreign policy official, Agha Shahi, on the nuclear issue -- at that time the overriding concern of U.S. policy -- and listened impassively to Pakistan's alarm about Soviet activity in Afghanistan. Relations reached a low point Nov. 21, when a Pakistani mob sacked the U.S. embassy in Islambad, killing two Americans and four Pakistanis.

The sudden U.S. turnabout to a position as Pakistan's great friend and protector took place literally over the weekend following the Soviet invasion The day after his telephone call to Zia, Carter spoke of "a longstanding [U.S.] relationship of friendship and mutual support with the Pakistanis" as if existing ties were calm and stable. But to Pakistan, as Shahi would say later, it had been a dizzying series of "ups and downs." There was and is trepidation that Washington could shift again overnight.

Second, Washington's new Pakistan policy was too highly publicized, and with too much attention to U.S. needs and too little attention to Pakistani sensibilities.

One of the elements in Carter's overnight reversal was the political need at home to do something dramatic to stop the Soviets in Southwest Asia, an imperative the canny Pakistanis sensed at once.

"Pakistani rejection always was a possibility, and the higher the visibility, the greater the risk," said a U.S. diplomat with long experience in that region. But the decisions were made quickly at the very top, with little input from specialists in Pakistani affairs.

Behind the Pakistani reticence was a steady drift in recent years away from the former reliance on the United States and toward new Islamic and nonaligned credentials. The rise of Arab oil power since 1973 provided a new and nearby center of material and political support. In this context, a highly visible return to a U.S. embrace -- especially at a time of high tension between the United States and revolutionary Islamic Iran -- could endanger Pakistan's most important and reliable connections.

Washington, however, seemed not to understand that times had changed. It seemed to take it for granted that Pakistan would leap at the chance to return to the U.S. orbit in the image of decades past.

Third, there was too little benefit in the Washington offer, in the view of Pakistan, and too great a risk of trouble with the Soviet Union.

Initial Washington deliberations envisaged $100 million in economic aid and $100 million in military sales loans to Pakistan. After a struggle with guardians of the tight budget, the sums were doubled. Although a stenuous effort in U.S. eyes, to Pakistan the $400 million aid offer was a disappointingly small share of what was expected and needed.

The package was presented to Pakistan as predetermined and immutable in advance of any assessment of its actual defense requirements. The touchy, proud Pakistanis suspected, correctly, that major hardware such as new jet fighters would be denied in order not to upset U.S. relations with India.

To make matters worse, the total sums leaked to the press here immediately after the two sides agreed in Washington talks to keep them secret -- and before Zia was informed of the figures by his emissaries.

The Soviet reaction was cause for deep concern in Islamabad. The Russians repeatedly have charged that Pakistan is permitting or actually fostering aid to Islamic insurgents in Afghanistan, and Moscow has issued numerous private and public warnings.

To make their pressure tangible, the Soviets early this month brought Russian troops in Afghanistan right up to the poorly defended Pakistani border. The United States, in contrast, is halfway around the globe.

In recent days, Islamabad indicated it would welcome a reaffirmation of the U.S. security commitment and the supply of U.S. economic aid, even while military aid remains unacceptable. The United States, embarassed by the publicized breakdown of its once "urgent" aid plan, has expressed interest in such a split-level arrangement.

If this can be done without fanfare or further mishaps, the plan sooner or later may come to fruition.