Macklemore & Ryan Lewis had written and produced a song called "Same Love," but they needed a special hook to finalize the emotional track. Like the rap duo, Lambert is from Seattle, though she had never met them before.
"I was sort of a last resort," said Lambert. "It was a match made in heaven."
Lambert was given "about two or three hours" to write the song's chorus and then record it the same night in front of the breakthrough newcomers, who were instantly impressed by the soft singer.
"They loved it. It was like this beautiful minute of silence after I sung the chorus," she recalled.
Others love it, too—including members of the Recording Academy. "Same Love" is nominated for the coveted song of the year at Sunday's Grammy Awards, pitting the rap song supporting gay love and acceptance against No. 1 smashes from Katy Perry, Bruno Mars, Lorde and Pink.
"Same Love" didn't top the charts—it peaked at No. 11 on the Hot 100—but it sold 2 million copies and helped propel Macklemore & Ryan Lewis to even greater heights. The duo is nominated for seven awards, including best new artist and album of the year for "The Heist."
"We'd probably all agree that the nomination for song of the year for 'Same Love' in particular is quite meaningful for us, in what the song has turned out to be and (what it) means to people," said Zach Quillen, manager for Macklemore & Ryan Lewis.
"We regard it as our highest accomplishment," he said.
The Grammys also will celebrate another song about gay pride Sunday with Sara Bareilles' "Brave," which she wrote to encourage her friend to come out of the closet. It's nominated for best pop solo performance and appears on her third album, "The Blessed Unrest," which is up for album of the year.
Keith Caulfield, Billboard's associate director of charts, said "Brave" could be getting a boost because of its Grammy nominations.
"It does seem like something happened since the Grammy nominations came out in early December. You can probably tie the two together," he said of "Brave," which reached its peak at No. 26 last week.
Lambert, who is openly gay, said having her first mainstream song be about a topic that's close to home and nominated for a top Grammy at the same time is a blessing.
She said it also has encouraged her to be honest in her own music. She released an EP, "Welcome to the Age of My Body," in December and it features a spinoff of "Same Love" called "She Keeps Me Warm"—a refrain from the original track.
Lambert signed to Capitol Records and will release a full-length album this year. She plans to sing about topics from female empowerment, fat shaming and domestic violence.
"I think people are figuring out there's no formula anymore. The things that used to work for record companies don't necessarily work," she said.
The Grammys will air live on CBS from the Staples Center in Los Angeles.
Follow Mesfin Fekadu at twitter.com/MusicMesfin