On the opening night of the Democratic National Convention, when Sen. Edward M. Kennedy telephoned President Carter to say he was ending his candidacy, the victor responded with an invitation.

He hoped, Carter told Kennedy, that the senator would be able to join him on the podium for Thursday night's finale to recreate the ritual tableau of unity, to help bury the party's differences and reconcile the opposing factions for the tough campaign ahead. The senator said he hoped so, too.

When Carter hung up, he was clearly pleased. He told one of his advisers that Kennedy had given him a "tentative yes."

For the next 72 hours, both sides spent a lot of energy and brain power making sure that the president's invitation would be accepted and that Kennedy would do, as he did tonight, the "right thing" for Democratic unity.

The nation's two most prominent Democrats and their company of aides treated the convention delegates to deft political performances that were at times like classical ballet, at times like old-fashioned hardball.

The shadow-dancing involved graceful turns and glamorous twirls, tense negotiations and angry exchanges. In the end, Carter forces came away ecstatic, having gotten the two things they wanted most -- the nomination and Kennedy's show of support.

Meanwhile, the Kennedy forces left town with the pleasant conviction that, while they lost the nomination, they won the convention.

The Monday night phone calls came in the wake of Carter's victory on the rules fight that guaranteed him the nomination, and there were some in the Carter high command who were not quite so confident about that "tentative yes" Carter felt he had received from Kennedy.

They thought Kennedy was still in what one called "a bargaining position." In Kennedy headquarters at the Waldorf Astoria, the senator and his own advisers thought so, too.

Kennedy wanted very much to be on the podium at the convention's end -- a show of political unity in 1980 would be important to his own political prospects in 1984. But Kennedy also intended to use the prospect of his endorsement of Carter and his appearance on the nominating podium as a lever for getting his own way on the economic policy matters that have been the core of his presidential campaign.

The ordeal proved especially arduous for the president's advisers. Carter and his high command have a history of being better at defeating other politicians than they are at getting along with them. The president's advisers came within a few moments of one stormy blow-up during the Tuesday platform fight that would have shredded their hopes for a unity pact.

After considerable discussion within the Carter command, the president's advisers decided to go all out to win their fight against Kennedy's economic plank, the one calling for a $12 billion antirecession program.They decided to press the fight, despite the fact that their position was opposed by organized labor, the bedrock of party politics, and was anathema to the party's liberal tradition.

Carter's delegate-counters were predicting that they would probably be defeated by some 300 votes in a roll call. The Carter command, nevertheless, told the network of whips to go all out.

The Carter tactics on the convention floor, trying to turn around a lost cause, served mainly to inflame the Kennedy partisans, who then won angry allies among labor delegates who had come to the convention supporting Carter. a

Then Kennedy made his convention-stopping speech.Suddenly, Carter delegates and Kennedy delegates were cheering as one for Kennedy and his minority plank. The Carter officials, realizing the peril of their political situation, began frantic efforts to achieve a compromise -- a voice vote that would spare the president an embarrassing roll-call defeat.

The Carter advisers were ready to cave in on the crucial Minority Plank No. 3, but the Kennedy aides, flexing their newfound muscle, pressed for a concession on four planks, including their wage-and-price controls plank.

At the podium, House Speaker Thomas P. (Tip) O'Neill Jr., the convention chairman, decided the impasse ought not to paralyze his convention any longer. He told Carter counsel Tim Smith that he was going to begin the roll call -- and, a mountain of parliamentary strength, he began moving toward the microphones.

Smith grabbed a telephone and demanded to talk to his boss, Hamilton Jordan, back in the Carter trailers. Smith yelled into the phone that all would be lost if Jordan didn't decide fast. As the speaker was nearing the microphones, Jordan gave a quick okay to yield on all the wage-and-price plank.

In a moment that was the parliamentary equivalent of Laurel and Hardy, the modestly built Smith raced along the podium in pursuit of O'Neill. At the last moment he managed to reverse the speaker's course, shouting that a compromise was ready. Then Smith conferred with Kennedy aide Carl Wagner, also on the podium, to make sure that the compromise was indeed set. It was.

The speaker went back to the microphones and led the convention through four voice votes, makin all of the calls himself. The compromise worked out as planned. The speaker declared that the Kennedy forces won on the $12 billion antirecession plank and two others and that Carter's side won on rejecting wage-and-price controls. The embarrassing roll calls were finessed. Kennedy got his victory on the issues. Carter continued the emotions of the moment and prepared the ground for final reconciliation.

In a real sense, Kennedy had saved the Carter forces from themselves. In their zeal to defend their economic policy, the Carter officials had inflamed the convention, and it was Kennedy's dramatic speech that gave them the reason and the rationale for yielding, just in time.

The Carter-Kennedy peace treaty was made final Wednesday in a series of deft exchanges that dealt with the "platform report" the president was required to file two hours before his name could be place in nomination. In that report, Carter was required to set forth any reservations he had about the platform. Kennedy and Carter aides today offered this account of those meetings:

About 10 a.m. Wednesday, Hamilton Jordan rode to the Waldorf Astoria to meet with Paul Kirk, his counterpart on the Kennedy side. The two men agreed that they would not try to "negotiate." Instead, Jordan would "inform" Kirk about the platform report -- then being drafted at Carter headquarters -- and Kirk would "inform" Jordan of Kennedy's reaction.

The two competing strategists say they tried hard to deal cordially with one another, but Kirk could not help complaining about a Jordan comment, quoted in that morning's New York Times, that the Carter side needed the support of Kennedy's people, but did not need Kennedy himself. Jordan assured Kirk the quote was mistaken, and the session got down to business.

Jordan "informed" Kirk that the Carter camp would not endorse the Kennedy-backed platform plank calling for a $12 billion federal program to create jobs for the unemployed. Kirk said that a disavowal would be a big political mistake. Jordan replied, in essence, that the politics of the move was his business.

As soon as Jordan left the Waldorf, Kirk got on the telephone to alert AFL-CIO President Lane Kirkland, auto workers president Douglas Fraser and House Speaker O'Neill to Carter's decision not to endorse the jobs plank. The labor leaders and the House speaker, who were already in steady contact with the Carter campaign on the issue, agreed that disavowal would be a serious mistake.

At 2 p.m., Jordan came back to the Waldorf, bringing with him Stuart Eizenstat, the president's chief domestic adviser, and a draft on the platform report. The labor leaders apparently had some impact on Carter, because the president had switched to a fuzzier statement suggesting that the jobs goal was desirable but the means -- a federal program with a big price tag -- was not.

Kirk, who had been joined by Kennedy's top issues man, Carey Parker, again warned that Carter would make a political mistake if he rejected a plank that would give the Democrats a specific program for fighting unemployment. According to Kennedy aides, Jordan replied that it would be a bigger political mistake to agree to an expensive new federal program when the voters seem to want fiscal austerity.

Carter officials say that the president's aides outlined the provisions of the Carter document and then asked if there were any phrases the Kennedy side wanted to include. They said the Kennedy aides did not suggest any, but asked about the cost of the program Carter instends to propose.

The Carter side supplied a figure, which both sides agreed not to make public. The Carter officials say the Kennedy aides did not ask them to include the dollar figure in the president's platform statement, and that they did not intend to do so.

Jordan went back again to Carter headquarters at the Sheraton Centre. Shortly after six, he was back at Kirk's suite in the Waldof, this time bringing a "nearly final draft" of the platform report. The language was still fuzzy, but to Kirk it seemed to say that Carter would ignore the jobs program in the platform and pursue instead an economic program of his own that would lead to "a significant reduction in the unemployment rate."

Kirk, knowing that Kennedy would not be satisfied, got back on the telephone with Kirkland as soon as Jordan left the hotel. What happened next is unclear, but within half an hour Kirk got a frantic telephone call from Jordan.

We're taking another look, the Carter aid said. Hold on a few minutes and we'll call you with some new language.

Ten minutes later, Eizenstat called to say that he had worked out some changes with Kirkland.

The major addition was a new sentence in which Carter said he would "accept and support the intent behind" the jobs plank and that he would "implement its spirit and aims." Some additional wording referred to federal money for the jobs program -- pointedly mentioning no figure but saying "the amount needed . . . will necessarily depend upon economic conditions."

For the Kennedy people, this sudden twist led to a reappraisal of what ought to be done. Until the changes had been made, it seemed to Kennedy aides that the senator probably would not endorse the president. To do so, after Carter had rejected the platform plank that Kennedy had stressed most of all, would amount to a betrayal of the basic Kennedy constituencies.

But the new language made an endorsement possible.

"We were certainly not prepared to put out a statement saying 'Hosannah! This is everything we wanted!' because it wasn't a Kennedy adviser said. "But the choice was stark and clear. You have to keep Ronald Reagan from being elected."

And Carter would have a much better chance of doing that if the party were united behind him.

By 7 p.m., Kennedy was settled in his Waldorf suit with Kirk, Parker, speechwriter Robert Shrum, personal aide Rick Burke, and John Douglas, a Washington lawyer whose campaign role is simply "close friend." As the platform debate droned along on the television set, the candidate and his people put together two differ versions of what he might say later that night after Carter captured the nomination.

One alternative, prepared by Parker and Shrum, was a two-page statement that described in some detail the flaws in Carter's platform report and expressed "regret." This statement included a blast at Reagan and a general call for Democratic unity -- but did not endorse Carter's candidacy.

The other version, put together by the whole group, was short and simple. It blasted Reagan, praised the Democratic platform and added a personal promise from Kennedy to "support and work for the reelection of President Carter."

For the next two hours, the Kennedy group discussed the alternativesl stopping now and then to have a snack or watch the convention on TV. Then Kennedy heard a network floor correspondent reporting that the Kennedy forces were going to submit "points of order" that would delay the presidential nomination so long that Cater's moment of victory would not come until long past midnight. The senator immediately called Carl Wagner, his campaign floor manager. "Let's stop that stuff," he said.

"The point was, we didn't want to get into this position of spoiling the thing," a Kennedy aide explained later. "It was Jimmy Carter's night. He deserved it. And it wasn't going to do Kennedy any good if it let his people get out of control and mess things up."

As the discussion in the room continued it became clear that the same kind of reasoning applied to the decision on endorsing Carter. Kennedy's advisers felt strongly that the senator's stirring speech Tuesday night and his victories on the platform debates had made this gathering, in a way, Kennedy's convention mor than Carter's

To refuse to back the delegates' nominee would suggest a churlishness that could undermine the respect and affection the loser had earned from his fellow Democrats. On the other hand, Kennedy still felt an obligation to take a stand for the umemployed.

But the group concluded that Kennedy had done all he could. He had a minority of the delegates here, yet had won at least as many of the battles as he had expected when he came to New York last Friday. So the decision was made to stop fighting and rejoin the team.

As soon as the Texas delegation east the votes that assured Carter's renominatin, Kennedy told his staff to copy and release his shorter statement -- the one that promised to support Carter in the fall. He called his New England campaign director Thomas P. O'Neill III, and told him to have the Masachusetts delegation move the make Carter's nonimation unanimous.

There was one thing left to do. Kennedy got on the telephone to congratulate the party's nominee. The senator and the president, according to Kennedy aides, had a short, perfunctory conversation. "Mr. President, I want to congratulate you," Kennedy said. "I will support you."

Carter replied, they said; "I knew you would all along."