The ending of The Spy Who Loved Me resolves in three steps: the stolen submarines destroy each other, Atlantis is destroyed, and Anya cannot bring herself to shoot Bond. The nuclear threat ends when Bond tricks the two stolen submarines into firing on each other, which turns Stromberg's own weapons against his plan. Bond then reaches Stromberg's base, kills him and rescues Anya, and torpedoes from the USS Wayne destroy the base while the pair flee in an escape pod.
The emotional beat is the gun. Anya raises Bond's gun to take revenge for her dead lover, Sergei Barsov, and then cannot fire, and the two embrace. Anya's choice not to shoot Bond answers the title: the spy who loved him spares him. The setup for that moment starts in the ski chase, where Bond kills Barsov while escaping, and it is confirmed in the Sardinia stretch, when Anya learns who killed him and vows to take revenge once the mission is done. Between those scenes the film keeps the debt open through the truce in Egypt, the cover story as married marine scientists and the escape in the Lotus Esprit submarine car. In my opinion, that long delay is why the scene works: she has had a whole film to decide.
The mechanics of the finale are also tied to the film's origins. Ian Fleming's estate allowed only the novel's title to be used, so the story, including the Liparus swallowing the USS Wayne and the plan to fire missiles at Moscow and New York, was written fresh. Production accounts summarized on Wikipedia add that legal action by Kevin McClory over SPECTRE and Blofeld led Albert R. Broccoli to drop those elements. That is why the villain is Karl Stromberg, with a nuclear plan and an underwater city, rather than a SPECTRE scheme.
A comparison with the rest of the series, as opinion: this is the tenth official EON film and the first made without Harry Saltzman, and it ends on a choice between two agents rather than on a purely mechanical escape. The Man with the Golden Gun, released just before it, has a different villain setup. Here the final image is quieter: their superiors watch from a ship as the pod floats at sea, a restrained close after the scale of the tanker and the underwater set that Pinewood's $1.8 million 007 Stage was built to hold. Jaws also survives his fight with a shark, which leaves him free to return as a villain. For the previous film, see The Man with the Golden Gun, and for the next, see Moonraker.