As a child, Stephen Sondheim lived a few blocks from the American Museum of Natural History, but he hadn’t been back in a while, so on a recent rainy night, in search of the PEN America Literary Gala and his friend Meryl Streep, he found himself disoriented. Streep was going to give him an award for Literary Service on behalf of the organization, which advocates for persecuted writers. He came to the diorama of Peter Stuyvesant in Dutch Manhattan. “If you get rid of the Indians, it looks like Barbra Streisand’s compound!” he said. It put him in mind of a Rodgers and Hart line about Peter Minuit buying Manhattan Island: “For twenty-six dollars and a bottle of booze.” He mused on a rhyme he loved. “Yip Harburg rhymed ‘everybody’ with ‘ladeedadee,’ ” he said. “It’s really terrific.”

Out of the gloaming, Streep appeared.

He: “Hi there!”

She: “Hi-i-i there!”

Streep had on a white shirt over black-and-white striped pantaloons. “It’s my springtime outfit,” she said.

“It’s your harlequin outfit!”

Sondheim asked Streep if she was a regular at pen events. “I came because I love you,” she said.

Where to next? The summer-stock theatricality of finding each other dissipated as the pair walked along the museum’s Stygian passageways. Attendees in black tie were beginning to stream in. Sondheim told a joke whose punch line was “I don’t care. It’s still kreplach.” He added, “That’s a profound joke.”

A pen guest approached Streep and asked her to pose for a photo holding a sign urging Russia to free the Ukrainian filmmaker Oleg Sentsov. “I don’t have social media,” she responded. But pen does, so she complied. (The picture ended up in the KyivPost.) Then, after wandering past the giant clam and the embalmed squids, they found the Milstein Hall of Ocean Life. “I remember this as a sort of atrium,” Sondheim said. Someone took a picture of him, puckish grin on grizzled face, leaning on the railing, with Streep tilting her head toward him, sorority-girl-like, the blue fibreglass whale hovering in the background. Sondheim had been playing around with whale metaphors earlier. “Whales and dinosaurs? It’s almost too easy.”

Once seated, they set out to tell the story of their friendship.

Sondheim: “Let her do it. Then I’ll correct it.”

Streep: “I didn’t have to bring my husband, because there you are!”

Sondheim (triumphant): “Now you have a portrait of Meryl’s marriage. It’s called ‘The Bickersons.’ ”

They first met more than forty years ago, when Streep had a bit part in Sondheim’s adaptation of Aristophanes’ “The Frogs,” at Yale, a production that was staged half in and half out of a pool. (“Chorine Chokes on Chlorine” was her suggested headline.) “I don’t think he even noticed me,” Streep said. “He was a god.”

Sondheim (demurring): “Oh, I’d only written a few shows. ‘West Side Story,’ ‘Gypsy,’ and ‘Forum.’ ”

Just ‘West Side Story,’ ‘Gypsy,’ and ‘Forum’?”

“And ‘Anyone Can Whistle.’ They stripped my epaulets after that, as they say.”

True collaboration waited until 2013, and the movie version of “Into the Woods,” in which Streep played the witch. He wrote a special song for her and she asked him to sign the sheet music. “Don’t fuck it up!” he wrote on it. Both agreed that she didn’t, but the song was cut.

In the meantime, their friendship grew through one of Sondheim’s favorite mediums, games. Natasha Richardson and Liam Neeson hosted holiday parties that included charades, in which Streep participated. Mia Farrow brought Sondheim to one.

“I play a different kind of charades than Meryl does,” he said. “I play running charades, in which there are two teams in relay. She likes to play the kind of charades where her team makes up all the things and our team acts them out and they giggle at what assholes we are as we’re doing it.”

Streep replied, “His version is too complicated to do when you’re drunk.”

The room filled. The awards were given. Talk turned to children (hers) and art (his). They have hopes for a new collaboration, but, for now, they wish they saw each other more. They have houses near one another in Connecticut, but they’re busy: He’s working on a Buñuel adaptation. She’s preparing to play Katharine Graham in Steven Spielberg’s version of “The Pentagon Papers.” But that isn’t the real reason.

“We plan—” Sondheim began.

“—and then he cancels,” Streep said.

“Or you do! And there’s a third person, and that’s Christine Baranski, who does a lot of cancelling.” This they agreed on: Baranski was the problem.