He posted the song on SoundCloud to impress a girl in time for prom, but that didn’t work. His luck turned and he was named prom king, thanks to the tune’s initial popularity. But then the prom queen dissed him, too.

So it goes in the lonely but flourishing life of Khalid, who has become one of the most fun success stories and promising young R&B singers of pop music’s social-media-ruled era thanks to his hit “Location.” But man, senior year of high school was rough for the teen from El Paso, Texas.

“We were supposed to go out and do a dance together, but she wouldn’t dance with me,” the real-life Khalid Robinson, 19, recounted of his experience with the prom queen. “It was really sad. But then all my friends got around me and danced with me instead, and it turned into this beautiful thing.”

“Location’s” success also turned out quite lovely.

One of many songs Khalid (“kah-leed”) posted for free before signing with RCA Records last year, it racked up a million streams by the end of the school year. Then, on his graduation day — right on serendipitous cue — the song went hyper-viral when reality-TV and gossip-column star Kylie Jenner posted it on her Snapchat account. All thoughts of college were soon off as record labels came calling.

A sure sign of Khalid’s burgeoning fame: He went from playing a Go 95.3 promo show in March at the Fine Line to headlining Myth nightclub, a show that had to be relocated from First Avenue due to demand. The bigger venue also sold out instantaneously. This fall, he will be playing arenas as an opening act on Lorde’s tour.

“I really wanted to keep expectations low and play small, intimate venues on this tour,” Khalid said last week by phone before a show in Philadelphia, where our call was twice interrupted because fans recognized him on the street. “But I also don’t want to let people down who can’t get in.”

Earnest, affable and polite in conversation — he even apologized for the interruptions, as if they were his fault — the singer sounded less conflicted about this newfound fame. He’s amazed by the swiftness, but he also sounded clearheaded and confident about it.

That morning, Khalid was all over the web again with “Silence,” a new song produced by electronic-dance music star Marshmello. With the hook, “I found peace in your violence,” the song reflects the dejection he said he felt moving around a lot as a kid, since his mom served in the military. (His dad died in a car accident at a young age.)

“I’ve felt like an outcast most of my life, being in multiple high schools and being a military child,” he explained. “The line ‘I found peace in your violence’ is about all the noise and disruption I experienced being an outcast, and finding peace in it and using it to form my creative vision.”

That’s a good synopsis of his full record, “American Teen,” a widely acclaimed debut full of atmospheric, beat-driven but melodic and melancholy tunes, which sound part Frank Ocean and part Lorde. As in “Location” — in which Khalid urges a girl to upload her whereabouts to him via her phone — many of the album’s songs reflect the virtual romanticism of modern teen life, with cellphones and social media being a big part of the song and dance these days.

Here’s how Khalid explained the origins of these songs and answered other questions in our interview.

Q: Do you think it’s a good or bad thing that kids nowadays are living out their romantic pursuits in large part via text messages and social media?

A: It’s almost like it’s vital. If you don’t text your relationship partner — even if you just saw them in person — it’s like you’re doing something wrong.

It wasn’t like I was specifically wanting to write songs about technology. It’s just what I lived, what I was experiencing growing up. Even though it’s a big difference from the way things were, I feel like it’s still essentially the same sort of love, just a new way of expressing it. It’s a lot like the way people look at and experience music today: I feel like a 19-year-old like myself still experiences the same kind of excitement for music as a 39-year-old did when they were my age. It’s just different tools.

Q: How wild a life change was it for you when “Location” went viral?

A: It’s crazy to think about a song I made in the middle of my senior year of high school being so huge. My mom was actually in the studio when I made it [laughs]. Then I released it on SoundCloud, and it did so well. I had to make the decision then if I wanted to do this for life. Singing for me was definitely going to be a part of my life regardless. It was already a big part of my life and my mom’s life.

I wrote music as a form of therapy. With “Location,” and all the other songs around it, my music turned into therapy for others. And that’s something I really love and am blown away by. I wanted to be a music teacher when I grow up, teach other people to express themselves like this, but now I get to do it, and it feels way better!

Q: Another of your standout songs, “Young, Dumb & Broke,” sounds like a celebration of those traits. What inspired that?

A: It was my expression of just accepting the characteristics I had at that time, and not caring that older people might look down at us. It’s like, “Yeah, I might be young, dumb and broke, but I still have so much love to give.” It’s also about not seeing love as a commitment at my age, not thinking I need to be in love forever. I’ve met so many different people, especially as a military kid, that I know relationships don’t always last. And that’s OK.

Q: How did moving from upstate New York to El Paso in your senior year affect you?

A: It was the move that changed my life forever. I was heartbroken to have to leave my senior year, and the moment I left I lost communication with most of the friends I had in New York. But I was able to make new friendships and kind of rediscover myself. I wrote my first song in El Paso, too, so it definitely changed my life for the better. Now, I hang onto El Paso like I was born and raised there.

Q: Your music reminds me a lot of a Minnesota kid with a similar story to yours, Spooky Black, aka Corbin. Are you a fan of his music?

A: Yes! He’s been one of my favorite artists. His song “Without You” I’d say I heard when I was in the 10th grade and listened to it a lot. I really liked the melancholy that he carries, the way his voice flows over smooth, kind of ghostly tracks.

Q: What’s your friendship with Lorde like?

A: She was actually one of my biggest inspirations when it came to making music. Then I met her, and she was just super-nice to me. The discussion of the tour got me so excited, because I will get to see one of my favorite performers doing her show every night. I just saw her for the first time in my life at Coachella, and it was breathtaking. She’s one of the advocates of the rebellious power of youth. She came at a very good point of my life a few years ago, and helped me feel empowered when I needed it.

Q: You starred in a lot of musicals at school growing up. Did that help now that you’re suddenly being thrown out in front of big crowds to sing?

A: It helped me a lot, especially to get over stage fright at an early age. It taught me how to open up on stage. I miss doing musical theater a lot, actually. That’s an area I would like to venture into when I get a little older. I would love to go out and do productions within the community, or support productions in El Paso high schools and the community. Musical theater programs in schools are depreciating. I’d like to be someone who helps change that.

Khalid

When: 7 p.m. Sat.

Where: Myth, 3090 Southlawn Dr., Maplewood.

Tickets: Sold out.