Image copyright Getty Images Image caption Maggie Rogers: "I finally feel like I'm finding my footing."

Maggie Rogers' story reads like a fairytale.

Two-and-a-half years ago, she was a student at NYU's Institute of Recorded Music when Pharrell Williams dropped in to hear her class's work.

As the superstar listened to Rogers' nimble electro-folk song Alaska, his face went from studied concentration, to astonishment and finally adoration.

Turning to the singer over the song's dying notes, he declared: "I have zero notes."

The session was filmed and blew up online. Rogers quickly found herself in the middle of a record label bidding war, and set off on a world tour, telling the story of that video over and over again.

"There are a lot worse things to be than 'The Pharrell girl'," she told the BBC in 2017.

"He always continues to creatively challenge himself, whether it's in music or film or fashion. I have all the same ambitions, so I find it really inspiring."

But what happens to a viral star once the virus dies out? Rogers' story had such a neat beginning, middle and end, that it was hard to imagine what came next.

That, she says, is exactly what she's spent the last two years figuring out.

"So much happened so quickly," she recalls. "My very private life became public almost overnight, and in this way where I had no control over it.

"I was really scared and I was really overwhelmed."

Glastonbury tears

Completely by chance, I witnessed Rogers' anxiety in real time at 2017's Glastonbury festival.

She'd just played to a packed-out audience on the John Peel stage (where she duetted with Declan McKenna on a cover of the Spice Girls' Wannabe) when she was whisked away to chat to BBC Radio 1.

On arrival, a producer placed her in front of an upright piano and asked what she'd be playing.

"I didn't know I was supposed to play," she said, looking terrified. "I haven't prepared anything."

Five minutes later, the red light went on and Rogers gave a flawless rendition of On & Off, a standout track from her debut EP. But as soon as the performance was over, she ran away in tears.

"That actually now doesn't feel so much of a big deal," she says, recalling that day, "but I think the pressure was [that] nothing felt like it was happening on my terms.

"So much felt like it was happening to me. And I know I have responsibility and I have agency in it, but it was just really complicated."

The pressure was so much, that the 24-year-old wondered whether becoming a musician - a dream she'd carried since her childhood in rural Maryland - was worth all the pain.

"I love music. I've never had any doubts about the music," she explains. "But the reality of being a professional musician is your life is only about 30% music.

"So I was like, 'Maybe I'll not do this, and have way more music in my life and maybe that'll make me way happier.' I was weighing that."

Rogers suffered writer's block for two years before finally stepping off the treadmill in late 2017.

"The music is always there, you just have to be still enough to listen," she said in a handwritten letter to fans. Then she left the US and didn't come back until she was ready to make her debut album.

"It was five weeks," she laughs, protesting at my melodramatic depiction of her break. "I went on summer holiday!"

"It's crazy because people are like, 'You really took your time with the record' and I'm like, 'When the hell else would I have made this thing?' I wrote and recorded it in four months. I can't imagine doing it any faster."

Image copyright Capitol Records Image caption The singer writes and produces all her own material, as well as conceptualising and choreographing her videos

The turmoil of the last few years is scrawled all over her album, Heard It In a Past Life - a smart and surprising collection that follows Rogers as she navigates the choppy waters of early adulthood.

"I saw my feet right down below me / Saw the whole room move around me," she sings on Past Life, a first-person account of the "Pharrell moment"; while Light On describes her mounting panic as the video went viral.

"Would you hear me out if I told you I was terrified for days?" she confesses. "Crying in the bathroom with everyone around me saying, 'You must be so happy now.'"

"I feel like we always talk about change on either side of it, but I wanted to describe what it was like being in the middle of it," she says. "Because that's where I was. I was in the eye of the storm for a long time. I needed a second to figure who I was."

Fighting sexism

As well as mirroring Rogers' personal evolution, Heard It In A Past Life chronicles her development as a singer-songwriter; with nods to the likes of Joni Mitchell and Carole King in its quieter moments, and the driving 80s pop of Taylor Swift and Haim on Retrograde and Give A Little.

Having written and produced the entirety of her debut EP, she opened herself up to collaboration for the first time, co-producing tracks with Greg Kurstin (Adele), Kid Harpoon (Florence + The Machine) and Rostam Batmanglij (Vampire Weekend).

To make sure she wasn't overruled or overshadowed, Rogers created a mood board for the album ("red, blue and silver, lots of movement, lots of photographs taken on film") which she carried from studio to studio with her.

"I'll put the mood board next to the computer and once we're trading off on the mouse or moving around the studio, I can always be cross-referencing whatever we're making against my original vision to make sure it still feels like what I wanted it to," she explains.

She's credited as a writer, arranger and co-producer on all 12 of the album's songs - an important point, given the number of interviewers who complimented Alaska by saying: "I love that song Pharrell wrote you".

"I find, as a woman and as a producer, I spend a lot of time convincing people I actually did the work," she sighs.

"I'll say, 'Oh, I produced this,' and they'll be like, 'What synth did you use and what outboard gear are you using?' And I'm like, 'Well, I can tell you but I shouldn't have to defend the fact that this is just what I'm doing.'"

Image copyright Capitol Records Image caption The singer mixes electronic sounds with samples she records from nature and live instruments.

Sitting with Rogers in a posh hotel next to London's O2 Arena, it's hard to imagine her as a bundle of nerves, strung out by success.

She's relaxed and confident - happy, in fact - as she shoots the breeze about life on tour ("I live on room service and reruns of the West Wing") and the sound effects artist she met after last night's gig.

"A lot of the sounds he was describing, he made with his mouth. Which was quite a weird conversation to be having in a bar at three or four in the morning."

Finishing the album helped clear her head, she says. But the real turning point came when she played the singles Light On and Fallingwater on the US comedy show Saturday Night Live last November.

"I felt this giant shift in the middle of that performance," she says.

"I was having a lot of sound issues in Light On. For the first verse, I couldn't hear anything and I was singing flat. Then, in the chorus, I found it, I got there.

"But that happening on Light On gave me fuel and tension for Fallingwater, and I just let go. I forgot I was in front of people and had this out-of-body experience.

"And that arc kind of tells the story of my career: I had such a hard time at first and I'm really enjoying it now.

"This record is so exciting because it feels like it's me saying, 'Yes!'"

Follow us on Facebook, on Twitter @BBCNewsEnts, or on Instagram at bbcnewsents. If you have a story suggestion email entertainment.news@bbc.co.uk.