Even before “La La Land” unspooled at festivals and in theaters, people were humming the tune “City of Stars” thanks to early teasers. The melancholy theme appears twice in the film — Ryan Gosling’s Sebastian sings a shortened version on a pier early on in the film, then later duets with Emma Stone’s Mia when the two have moved in together. The song has become an anthem of sorts for the film, and is one of two tunes nominated from the film for best original song.

Writer-director Damien Chazelle called upon his college roommate Justin Hurwitz to score the film and write the melodies for the six original songs. When it came to the lyrics, they hired the duo of Benj Pasek and Justin Paul, who are currently enjoying massive success on Broadway as the composers and lyricists of “Dear Evan Hansen.”

The journey to Oscar-nominated song was full of its own twists and turns. In what sounds like the plot to a romantic comedy, the lyricists essentially “stalked” Chazelle and Hurwitz for the job. “City of Stars” was originally written to be performed by Stone’s Mia, before ending up with Gosling’s Sebastian. And shooting the number in one take in a crowded apartment proved to be more of a challenge than expected.

Variety spoke to the two duos (Chazelle and Hurwitz, Pasek and Paul) about the unique collaboration that brought “City of Stars” to life.

In 2014, after the success of Chazelle’s “Whiplash” at Sundance, the pair began to work in earnest on “La La Land” with Hurwitz composing melodies for the film. Once they had them locked in, it was time to add lyrics. Hurwitz describes the process of meeting lyricists “almost like dating.” They met with a number of songwriters, and Pasek and Paul were recommended by their manager, Richard Kraft.

Paul: Richard reached out to us and said, “I just had lunch in L.A. with you guys. There’s these two guys, they’re young filmmakers and they met at college and they’re a duo. They’re just like you guys but they live in L.A. They’re developing a new project, a musical, and they need lyricists. I know you’re composer-lyricists but these guys are too talented and great, you have to work with them.”

Pasek: We jumped on the phone with them and we were really excited. You don’t often get the chance to work on a film using original music.

Paul says the duo “responded kindly, but not enthusiastically,” so he and Pasek decided to get on a plane and “show up on their doorstep and ask them to dinner.” It worked – they all went to dinner and really connected. And as if they didn’t already feel like stalkers, it turned out the friend they were staying with in Los Angeles lived in the same building as Hurwitz.

Pasek: When we got back from dinner, our car pulled in before theirs. They were like, “What are you guys doing here?” Had they gotten there first, they would have been convinced we were stalking them.

Chazelle: It was a coincidental stalking.

The next day, Pasek and Paul had a work session with Chazelle and Hurwitz, where they presented the lyrics to what would become known as “City of Stars.”

Pasek: When we began to speak with them and found out we were going to LA, we were sent an MP3 of the melody they’d been working on. They’d been working on it for so long and really developed the melodies, so it was our job to put words on top of them and how to make them function as song moments. We got this gorgeous melody called “Ballad” that at the time it was for Mia to sing. We heard this beautiful melody full of longing and melancholy but also hope and it contained so much emotion and storytelling, we were so incredibly excited about what they’d come up with.

Paul: We had come up with a lot of the lyrics on the plane ride over, then we worked late into the night to polish the lyrics. Then we took the elevator downstairs in the morning and went to Justin’s apartment and sang our version of what the song would be. And we just sort of started right in from that point.

Hurwitz: What they sang that morning is pretty much exactly what’s in the movie. There were some changes here and there, but it was practically perfect right then.

Chazelle: The first time I heard the lyrics, I was blown away. In some ways, there was a childlike simplicity to the language, yet it’s incredibly elegant and poetic. There were these flurries of poetic phrasing—“the smokescreen of the crowded restaurants”—so beautiful and yet in some ways, so simple. We’d tried to do dummy lyrics before but they didn’t slide into the song easily. This did, and it was a revelatory moment.

But at this point, the song was still set to be sung by Stone. That changed at the first read-through.

Chazelle: What hadn’t been clear on the page became clear in the read-through: that there was a redundancy. We were missing Sebastian’s voice. I originally thought his piano would be enough to externalize his inner emotions. It turned out not to be the case. Once you’ve established a language where people can sing their feelings, his character needed a chance to do that and balance it out. So we gave it to Sebastian and saved the song “Audition” for Mia’s big moment, which I think makes that number even more powerful.

During the three-month rehearsal and prep period, Chazelle also decided the song should be sung live.

Chazelle: The first draft of the script didn’t have the scene of them sitting at the piano. There was a different number, more uptempo. That was something that in prep we decided didn’t really fit the movie anymore. We wanted a number there to chart the crossroads moment when Mia is committing to her play and Sebastian is committing to the new band. We landed up on reappropriating it as a duet because we loved the idea of it as a recurring melody. So now Ryan introduces it alone earlier in the movie, then you re-hear it in full as a duet at the piano later in the movie. Once we landed on that structure, in talking about how to stage it, we landed on doing it live and doing it in a simple way to contrast with the two big numbers around it—“Planetarium” and John Legend’s “Start a Fire.”

Hurwitz: It’s a song about yearning. He sings it early on about their courtship after he asks her out on a first date. He’s excited but also very cautious, he’s had so many dreams that haven’t worked out for him. So it has that hopeful, optimistic sweetness, but also a sadness. When it’s reprised later on, their relationship is further along, but at this point in the story they’re making big gear shifts professionally. I love how it addressed both the relationship and the professional ambition and for that reason it felt like the other heart of the movie, along with the main love theme.

The duet was shot in one take on one afternoon; Chazelle estimates they did between 12 and 15 takes of the scene. At first, the number didn’t work.

Chazelle: It was slightly trickier than it looked. Initially we wanted the camera to glide over the piano from Ryan to Emma ,and in order to do that completely seamlessly, we basically needed a mini crane. Because we were in a real-life apartment and not on a set, we couldn’t fly in any walls and there was very little room for even the tiniest crane. We tried it and it wasn’t working. So we huddled in the corner and tried to figure out what was missing. We realized we had to treat it as the most intimate moment in the movie. You almost want to treat it like a love scene, you want the fewest people on set as possible, you want it to just be about Ryan and Emma and the camera. So we adapted it to do it on steadicam and it became just them at the piano. As soon as we got rid of all the machinery, we started to get magic.

Paul: The room they shot in was so small and we were all crammed in on one side of the room. Justin was playing live along with them … it was very exciting, very visceral experience.

Hurwitz: Any time there was live singing on set, they were singing live not lip-syncing. So I was in the other room playing an electric keyboard into their earpieces. That let them be free with their performances and take the space they needed to act it. So there was this great give and take, this pushing and pulling and responding to each other and you get a real, authentic performance.

Paul: They were in a playful mood, a couple times Emma even laughs and you see that in the take they used. I loved it. It’s so real to the moment and little imperfections are important to Damien and to the film that it feel real and authentic.

Chazelle: Those little moments you would not get if you over-rehearsed or over-choreographed. It was unlike the other numbers that had to be planned to a T.

“City of Stars” has become a big part of the film’s marketing, and almost the anthem to the entire movie.

Hurwitz: Damien would always say he wanted it to be the most romantic song in the movie when you see it. The second time you see the movie, you see it’s where the characters begin to diverge. It’s sort of the beginning of the end for them.

Chazelle: It was the melody that hit me like no other from the start, except maybe Mia and Sebastian’s theme. But it was a bit low key so I thought maybe one of the giant showstoppers would be everyone else’s favorites. So it’s kind of nice and surprising it’s sort of become the song that’s most associated with the movie.