A dizzying array of police lights flashed up and down the West Side Highway on a damp Thursday in May. President Trump was visiting the U.S.S. Intrepid, snarling traffic outside the Javits Convention Center, where Katy Perry was performing at a corporate showcase for her new partner, YouTube. The last time she was in the building was election night, when she had been preparing to toast the victory of Mr. Trump’s opponent.

For Ms. Perry, who prominently supported Hillary Clinton’s campaign, that party on Nov. 8 began “with everybody looking fancy and beautiful and high on their horses,” she recalled in an interview several weeks after her YouTube set. The mood rapidly shifted when word started to spread that Mrs. Clinton was not on her way there — news that Ms. Perry, 32, described as “traumatizing.”

“It was a revelation, it was a reckoning,” she said of Mrs. Clinton’s loss. She started downing drinks and reached out to the nearest person for physical support: Lady Gaga, also there to celebrate the election of the first female president. There they were, “Gaga and I just looking at each other, and being like, [expletive] it, we need to touch each other,” Ms. Perry said. And for a minute, two of the biggest pop stars in the world held hands.

[Sign up for our music newsletter, Louder.]

Alliances aren’t easily made in the superstar stratosphere, where elbows are often sharp. And Ms. Perry, who released her fourth major label album, “Witness,” on June 9, stands as one of the biggest successes in the industry, alongside Madonna, Beyoncé and Taylor Swift. She has sold 6.5 million albums and nearly 71 million digital songs in the United States, according to Nielsen Music; notched 14 Top 10 Billboard Hot 100 hits; performed at the 2015 Super Bowl halftime show; and landed a gig as a judge on the revamped “American Idol,” which is to return in September on ABC.