As Senate Majority Leader Howard H. Baker Jr. flew home to Huntsville, Tenn., last Friday for the weekend, he allowed himself to say for the first time that the AWACS fight was over.

"We have it won," he told his staff members, noting also for the first time that if the administration were not sandbagged at the last minute there would be at least 50 Senate votes to allow President Reagan's sale of sophisticated arms to Saudi Arabia.

Just as Baker was sensing victory Friday, the public perception in Washington had swung hard the other way. The sale appeared doomed, and its opponents were confident.

President Reagan was just preparing to return here from a 22-nation summit in Cancun, Mexico, and, with the vote on sale of the Airborne Warning and Control System planes scheduled Wednesday, he was determined to take no chances.

Reagan cleared his schedule to devote Monday, Tuesday and whatever time was needed Wednesday to private meetings with wavering senators, seeking to cement his victory on the first major foreign policy test of his administration.

The victory came in what White House officials believe was their only possible window of opportunity--after battles on tax cuts and the budget but before an election year when surmounting the strong protests of Israel would have been far more difficult.

The White House also managed a remarkable two-track lobbying approach. With Republicans, the appeal was to party loyalty and the need to support their president. Democrats were asked to be bipartisan and avoid dealing the president a defeat that would damage U.S. foreign policy interests. The contradictions were obscured, and the effort succeeded.

For many of the Republicans, especially first-term senators whose votes became pivotal, the experience was emotional.

One who succumbed to Reagan's persuasion said the president spoke quietly but with a sense of urgency:

"Once you supported me when I needed you. You worked to help me get here so we could get some things done, and now you want to leave me hanging here by my thumbs. You want to cripple me on the very first foreign policy test I'm facing. Don't let it happen to me. Don't let it happen to our country."

Iowa's Roger W. Jepsen, who switched back to Reagan, broke down and cried in a meeting with fellow Republican senators as he described pressures on him.

The persuasive tactics succeeded despite initial miscalculations within the administration that enabled Senate opponents of the sale to gain the early advantage. Reagan's men described their battle as an uphill fight and, in a sense, it was--thanks to the early fumbling. Many hailed it as a startling triumph, but one Republican legislator called it "a nice save."

The sale of the sophisticated AWACS radar planes as part of a package for Saudi Arabia was first presented at a National Security Council meeting April 1, two days after the president had been wounded in an assassination attempt.

Defense Secretary Caspar W. Weinberger told the meeting that no more than 35 senators would vote against the sale. Backed by White House officials, Weinberger overrode dissents by Secretary of State Alexander M. Haig Jr. and National Security Adviser Richard V. Allen.

The next day, Weinberger took the sale proposal to Reagan at George Washington University Hospital, and the president agreed to it.

By early last month, when the president returned from a month-long holiday in California following the tax and budget victories, the resolution opposing the sale had 50 signers.

The White House effort, initially Allen's responsibility, had scarcely begun as the resolution, introduced by Sen. Bob Packwood (R-Ore.), was gaining backers.

Under Allen's management, 37 internal meetings had been held during the summer involving representatives of all government agencies concerned with the sale. Participants met almost daily in the White House Situation Room and mapped strategy. "I was never able to determine one vote that came out of those meetings," said one White House official critical of the early effort.

On Sept. 2, Prince Bandar bin Sultan, Saudi Arabia's chief representative in the United States during the AWACS negotiations, flew to Baker's guest house in Huntsville with Undersecretary of State James L. Buckley to discuss what Baker then considered a sale in deep trouble.

Two major problems arose. First, Bandar was approached about obtaining Saudi assurances that the planes would be used in a way that would assuage those who feared for Israel's security. Then Baker said a prominent Democrat such as Minority Leader Robert C. Byrd (W.Va.), John Glenn (Ohio) or Sam Nunn (Ga.) was needed to help manage the sale.

Bandar and Baker stayed in close contact and, at one point, the prince used a telephone in Baker's office to phone his government to explore whether the Saudis would grant the United States joint control over the AWACS planes, a source close to Baker said. Bandar received enough of a go-ahead so that talks could continue.

Throughout September, Baker consulted almost daily with Republican Sens. Paul Laxalt (Nev.), Charles H. Percy (Ill.) and John G. Tower (Tex.), while the administration overhauled its approach to pushing the sale.

With Allen and Haig still fighting over turf and authority, according to White House and Senate sources, more prominent roles were given White House Chief of Staff James A. Baker III; his deputy, Richard Darman, and head of congressional liaison Max L. Friedersdorf. Baker was in command.

Glenn had indicated that, if he were assured about joint control of the AWACS planes, he might be the Democrat Sen. Baker sought to help promote the sale. But he backed away after the State Department indicated that new agreements had been reached with the Saudis only to have Haig appear before the Senate Foreign Relations Committee with nothing new to present.

A major breakthrough came at the end of September when Weinberger was testifying on the sale at a closed session of the Senate Armed Services Committee. Nunn suggested that the administration consider attaching to the sale proposal some form of legislation setting binding conditions.

According to Nunn, Weinberger was lukewarm to that idea, but Sen. John W. Warner (R-Va.) signaled an interest. The senators realized that a legislative proposal would face certain defeat in the House, where the sale was overwhelmingly opposed. But the next Sunday, Oct. 4, Nunn received a dinner invitation from Warner.

Warner also invited Glenn, James Baker, White House counselor Edwin Meese III and other administration officials to what became a discussion of how the White House had bungled the AWACS push and what could be done about it.

At the dinner, Nunn recounted yesterday, he suggested that Reagan put into writing a series of commitments designed to overcome senators' objections to the sale. The result became a tool the White House used with great skill, trying to rewrite or expand the letter to make it all things to all wavering senators.

When Reagan turned on the pressure, appealing personally to 46 senators for their votes, the letter became a convenient fig leaf. Senators who wanted to yield to Reagan's entreaties needed a reason, and the letter provided one in several cases. At least six senators mentioned the letter, which was kept secret until the day of the vote, in explaining their changes of mind.

Sale opponents had a tough time fighting what they could not see. Senator after senator was shown the letter at the White House and allowed, or even encouraged, to suggest language that would satisfy his personal concern. "We needed to give people a bridge to come over to our side," a White House aide said. "The letter of certification provided that bridge. It provided a justification for people to move over."

The letter also was a risk. By the time it had to be made public, hours before the vote, it had been rewritten so many times that White House assistants feared it might backfire.

Initially, they had decided not to make it public until the 11th hour in order to prevent the opposition from picking it apart.

"But, after a while, it became clear that there was a lot of danger in the letter as well, because we were afraid that it might be used as a justification that would cause us to lose someone we already had," one White House official said. Changes made during the last week to please senators had replaced language suggested earlier by other senators. "We were afraid some senator would take a look at the letter on the last day and tell us, 'You promised me the letter would say such-and-such, but it doesn't,' " the aide said.

Sen. Charles McC. Mathias (R-Md.) wrote one early change. He suggested the letter stipulate that terms of the sale could be changed only with congressional "participation" instead of "consultation," as the letter intitally stated. Reagan and James Baker approved. "I kept checking every subsequent draft to make sure that change was retained," Mathias said. It was, and Mathias voted for the sale.

In the end, no one balked when the letter was made public with its commitments that are not legally binding and stop short of assuring joint control after an initial period of training Saudis to use the planes.

Not all of the lobbying for AWACS involved Reagan's personal persuasion or the expanding letter's ability to ease concerns.

On Sept. 15, E.H. Boullioun, president of the commercial aircraft division of Boeing Co., sent a mailgram to 1,600 subcontractors, suppliers and vendors serving the company. It read in part:

"The Boeing Company doesn't establish foreign policy. However, in this case we believe President Reagan is correct in bolstering a friendly nation's ability to defend itself.

He also said Boeing would end AWACS production and warned that Saudi Arabia's attitude toward other "U.S. products" might be affected if the sale were vetoed.

Several senators said they knew of widespread support for the sale by American business, including the Bechtel Corp., Mobil and Pratt & Whitney, manufacturer of the AWACS jet engines.

Packwood discounted the effect of this lobbying. "With 90 percent of the votes, the president was 80 percent of the deciding factor," he said. James Baker said: "The president was once again underestimated."

Reagan had met privately with 22 Republican senators, 14 of whom voted with him. He saw 22 Democrats one-on-one, and 10 supported him, according to James Baker, who stressed the importance of Reagan's persuasive powers.

The result was an odd phenomenon. As they stood to announce they favored the sale, those whose switches gave Reagan his victory said they remained convinced that the sale was a bad idea.

Sen. Alan Cranston (D-Calif.), a leader in the effort to block the sale, tried to counter that such loyalty to a president against legislators' own interests was the sort of attitude that helped produce Vietnam, but he made no headway.

Shortly before the roll-call vote, when it was evident Reagan had won, another senator on the losing side, Edward M. Kennedy (D-Mass.) said: "In my 19 years up here, I have never seen such 180 degree turns on the part of so many senators. I have seen nothing that would justify this kind of reversal."