President Reagan was drinking after-dinner coffee on a red couch with Soviet leader Mikhail Gorbachev Wednesday night in the elegant library of his temporary residence on Lake Geneva when the superpower summit took a surprising and critical turn.

Secretary of State George P. Shultz turned to Georgi Kornienko, the Soviet first deputy foreign minister, and accused him of trying to stall summit negotiations on bilateral issues such as a civil aviation agreement. "You, Mr. Minister, are responsible for this," Shultz declared. Then, turning to Gorbachev, the secretary of state added forcefully:

"This man is not doing what you want him to do. He is not getting done what you want done."

The outburst prompted an appeal from Reagan to Gorbachev. "To hell with what they're doing," the president said. "You and I will say, 'We will work together to make it come about.' "

Reagan and Gorbachev then shook hands.

White House officials said yesterday the handshake on the couch marked a turning point in the summit and set in motion an agreement early the following morning on a joint statement on arms control and other issues -- although not before some final hurdles had to be overcome.

The officials who witnessed the Shultz episode -- and who are familiar with Reagan's private discussions with Gorbachev -- described the summit as one that took a roller-coaster route from rhetorical confrontation to impasse and finally to the joint statement and an agreement to exchange summit visits in 1986 and 1987. The two days of talks were marked by good-natured story swapping between the two leaders as well as moments when Reagan and Gorbachev seemed on the verge of deadlock.

According to these officials, the president's personal diplomacy ranged from impassioned appeals for his missile defense system to a nostalgic conversation about his most widely acclaimed film, "Kings Row."

The film came up as Reagan and Gorbachev took a walk toward a pool house last Tuesday, the first afternoon of their meeting. Reagan was irritated at Georgi Arbatov, the Soviet leader's top Americanologist, for describing the president as a "B-movie" actor. "Do one thing for me," Reagan said to Gorbachev as the two men walked along. "Tell Arbatov they weren't all B-movies."

Gorbachev responded that he had seen the 1942 film in which Reagan played Drake McHugh, a rake from the wrong side of town whose legs are amputated by a mad surgeon because of a romantic involvement with the surgeon's daughter. "Where's the rest of me?" Reagan exclaims when he discovers his legs are gone, an expression that became the title of his autobiography.

But the Soviet leader did not mention the title. "The one I liked was the young man without the legs," he said, asking Reagan what it is like now to see himself in such old films. "It's like seeing the son you never had," Reagan said, according to administration officials.

Such small talk was sandwiched between intense debates over Reagan's Strategic Defense Initiative (SDI), an attempt to develop an effective missile defense, which the Soviets have made their chief target of criticism. Gorbachev repeatedly denounced it and Reagan fired back with a description of his "dream" that nuclear weapons would be made obsolete.

On Tuesday afternoon, in a meeting attended by advisers to both leaders, Reagan and Gorbachev engaged in such strenuous arguments over the concept that officials said they thought the two leaders had reached an "impasse," at least rhetorically. At this point, Reagan suggested that he and Gorbachev take their walk on the grounds of Fleur d'Eau, the site of their first meeting. Gorbachev said he thought it would be a good idea to get some "fresh air" into the stalemated debate, and out the door they went.

Eventually they reached the pool house, where aides had prepared the fireplace ahead of time. As they sat before a blazing fire, Reagan handed Gorbachev four proposed guidelines for the Geneva nuclear and space arms negotiatiors. While three of the points were apparently not seriously objectionable, one of them, dealing with strategic defenses, was immediately rejected by Gorbachev.

The seeming impasse over SDI cast a pall over meetings Reagan had the next day with his senior advisers, according to several of them. The Soviets had called a news conference for 10 a.m. on Thursday morning. White House officials believed this was a ploy, to threaten the United States with a critical blast at Reagan's missile defense plan at the summit's end.

Officials said that at lunch with Reagan, White House spokesman Larry Speakes warned of headlines to come saying the summit had foundered on disagreement over missile defenses. Assistant Secretary of State Rozanne L. Ridgway said Americans were not yet "signed on" to Reagan's vision of strategic defenses. Shultz had a gloomy report for the president.

"We may end up with only an agreement to meet again," he said, according to an official who was present. "The Soviets are wary of a final statement. They are afraid Reagan will bang 'em on SDI and human rights. If there is no agreement on statements, it could all fall apart, except an agreement to meet."

Reagan then spoke up. "I believe Gorbachev is being political on SDI," he said. "He doesn't know how to get off of it."

U.S. officials believed a lot had been accomplished by then, but one said there were fears "the whole thing might collapse on us" because of disagreements over language on strategic defense in a final statement.

In a private session Wednesday morning, the disagreement over missile defenses was set aside as Reagan complained to Gorbachev about the Soviet human rights record and the Soviet leader responded with criticism of the United States.

Events took a critical turn Wednesday afternoon, when Shultz and Soviet Foreign Minister Eduard Shevardnadze reported to the leaders on the status of negotiations over a possible joint statement. While there was agreement on some areas, Shultz said, the biggest gulf was over what to say about the ongoing Geneva talks on nuclear and space weapons. A copy of the latest proposal from the United States was handed to Gorbachev.

The Soviet leader then barked out three sentences of new language. "He didn't need any option papers," one administration official said of Gorbachev.

The Soviet leader startled U.S. officials by his decisiveness at this moment. Gorbachev told Reagan that he wanted a joint statement to climax the summit, that he wanted to speed up the Geneva talks, that he wanted to embrace aspects of existing U.S. and Soviet arms control proposals and the concept of a 50 percent cut in weapons. He said the 50 percent concept gave the negotiators a "big marketplace" to work in.

After dinner, Shultz and the others returned. Gorbachev, after some resistance, agreed to verbal statements by each leader on Thursday. That assured "something would be produced" out of the summit, a U.S. official said, but Shultz then complained of Soviet foot-dragging on the bilateral accords, leading to the Reagan-Gorbachev handshake.

Shultz later told other U.S. officials that the Soviets were following their usual negotiating tactics. Progress resulted only after Gorbachev had "thrown the switch," he said. U.S. officials also said they resisted Soviet demands successfully. "At the final minute, the Soviets said, 'We want a successful summit,' " one U.S. official said.

Yesterday, Reagan told his Cabinet that he also swapped jokes with Gorbachev. One was about an American who says his country is best because he can walk to the White House and "tell the president he is doing a lousy job."

But a Russian responds that his country is better because he can go to the Kremlin and tell Gorbachev the same thing: that "Reagan is doing a lousy job running the United States."

Reagan told his Cabinet that Gorbachev laughed.