On a Sunday this month, it was midafternoon and Puth hadn’t eaten yet, but he was in his modest home studio, with its racks of vintage synthesizers, working out some ideas with songwriter Johan Carlsson.

He hopped on a keyboard with a distinct early-1990s vibe, gooey and a little cold, and began playing snippets of older songs: Toto’s “Africa,” Ol’ Dirty Bastard’s “Got Your Money,” SWV’s “Weak.” He hit upon a sound that made him happy — “like mixing Jodeci with Tears for Fears,” he said.

It was a few days before the release of “Voicenotes,” his second album, and the first one not quickly microwaved to completion in the immediate aftermath of an out-of-nowhere megahit. In 2015, Puth was an up-and-coming songwriter when he rocketed into the pop troposphere with the Wiz Khalifa collaboration “See You Again,” a moist lump of treacle from the “Furious 7” soundtrack. Other big hits followed, but none felt quite right to him.

“I was trying to figure out who I was musically in front of millions of people,” he said, seated by the pool in the back of his house. He wore a Puff Daddy T-shirt tattered with attitude, yellow Adidas sweatpants and chunky Alexander McQueen sneakers. His hair was flamboyantly shaggy, as if a clean swoop had hit a wind tunnel.

“Voicenotes” is a confident, impressive pop album, with ironclad melodies and frisky takes on 1980s funk and 1990s soul. It turns out that Puth is not the maudlin crooner who entered the spotlight, but rather a sophisticated pop marksman with a gift for spare, pointed arrangements — he produced almost the whole album himself — and detailed, vulnerable lyrics. He gets wronged by an older woman on “Boy,” and “LA Girls” is about how a whole city, and everyone in it, can break your heart. On “If You Leave Me Now,” he duets with Boyz II Men, and on “Change,” with James Taylor. His falsetto, on “How Long,” “Somebody Told Me” and more, is appealingly supple. All in all, it makes for one of the boldest pop albums of the year.

Getting here was not easy, though. For Puth, 26, the couple of years following “See You Again” were a juxtaposition of intense public success and equally intense private struggle. “A little bit of success, you think that I would be over the moon,” he said, “but quietly, it was really hard for me.”

He had several smash singles, including the treacle 2.0 of “One Call Away” and the sensuous Selena Gomez duet “We Don’t Talk Anymore,” and his debut album, “Nine Track Mind,” went platinum. But it was rushed: “For the most part it was just filler,” he said. Decisions were happening rapidly. In a particularly cruel example of record label alchemy, a version of his song “One Call Away” was released featuring Mexican starlet Sofia Reyes, ur-country gentleman Brett Eldredge and salacious R&B crooner Ty Dolla Sign. (Yes, that is a real song.)

And for someone who grapples with anxiety issues, being suddenly thrust into the spotlight was disorienting. “I’m already a very in-my-head anxious person,” he said. “I don’t really do well when I’m alone a lot because I’m alone with my thoughts, which is not good. It gets very freaky. The big misconception is when you get more famous you have more friends. I find that I’m alone more than ever now.”

He cried on Norwegian television. At a concert in Dallas, while singing “We Don’t Talk Anymore,” he cursed out Justin Bieber (Gomez’s ex) in absentia, prompting love triangle speculation. He flirted with two married “Access Hollywood” hosts. (“The Puthinator came out to play,” quipped Australian gossip site Dolly). He was captured by paparazzi with Hollywood wild-child Bella Thorne on a Miami beach, then, after she posted a picture with her ex, melted down on Twitter just a few days later.

“He was put into a very difficult position ‘cause the song ['See You Again'] was bigger than he was,” said Kara DioGuardi, the hit songwriter and onetime “American Idol” judge who taught Puth songwriting at Berklee College of Music. “I don’t think he was prepared for that.”

Usually it takes pop stars decades to recant their ways and lament the falsity of fame; for Puth it took about 18 months. “I can’t pretend that I can go on being that guy when I truly, truly wasn’t,” he said. “I’m the nerdy musician who likes to make mixtapes for girls in 7th grade. Now I’m just older, and I’m still doing that.”

By the time of the Jingle Ball at Madison Square Garden at the end of 2016, he’d begun to unravel a bit. At the show, he was beating his piano like a drum kit and jerking his body theatrically like the Incredible Hulk breaking out of Bruce Banner’s square slacks.

A few months later came “Attention,” the slick, lithe, panting funk vamp that announced Puth’s rebirth. It snarled, full of resentment about a woman attaching herself to Puth for the wrong reasons.

He now wonders if, during his brief flirtation with public life, his high-profile romances were more transactional than they felt in the moment. “I think I got — I’m trying to say this in the right way so I don’t get in trouble — it was more about the idea of me than actually wanting to be with me,” he said, “and I got that confused with actual love and romanticism.”

For all his success, there is something still tender about Puth. He carries himself softly, behaves considerately. In school, he was an eager student. “Driven, driven, driven,” DioGuardi said. “Always ready to answer a question, expound on why he thought something was good or bad. He stood out. He was quirky and funny.” When he talks about the work Babyface did on TLC’s “CrazySexyCool,” he notes how the intro is in B minor and then the next song, “Creep,” shifts to C minor. During the interview, when he heard a bird chirping in his backyard, he squawked back, “B flat!”

He learned piano from his mother and commuted from New Jersey to the Manhattan School of Music before heading to college at Berklee. During high school, he wrote jingles for YouTube stars, and later, in college, was briefly signed to Ellen DeGeneres’ record label after a YouTube cover he did — a duet version of Adele’s “Someone Like You” — took off in 2011. When “See You Again” became a smash, he was making his way as a behind-the-scenes force: Lil Wayne’s “Nothing But Trouble” began as Puth’s song lamenting Instagram models; he wrote Trey Songz’s “Slow Motion”; and he produced “Broke,” a madcap collaboration by Keith Urban, Jason Derulo and Stevie Wonder. (Yes, a real song.)

But even though he’s been working at becoming famous for so long, he’s still growing into his pop star presence.

There was a brief flicker of the 2015-16 Puth around the release of “Attention.” He went on “The Voice” to perform the song, in a tight red shirt, surrounded by flexible female dancers. “Voice” judge and new friend Adam Levine texted him afterward that he felt the performance wasn’t a true reflection of his artistry.

Levine was right. “It was fake,” Puth said. “It was an invention in my mind, a hypothetical that would work.” The next time he performed the song on television, he stripped it down with the Roots on “The Tonight Show Starring Jimmy Fallon.”

“You can have a career like Bruno Mars and not be seen everywhere,” Puth said. “I’m getting back my tortoise shell.”

And doing so is maybe allowing him to put his heart on the line again. In the studio with Carlsson, instead of getting mired in the skepticism and frustration that define “Voicenotes,” he was writing about how a new crush tingles:

I love the way

Those letters feel

When I write your name in my phone

Write your name in my phone, babe

This article originally appeared in The New York Times.

JON CARAMANICA © 2018 The New York Times