When Riz Ahmed, the rising British-Pakistani actor, came to New York to shoot the pilot episode of HBO’s “The Night Of,” in which he stars as a college student from Queens accused of murder, he sought advice from Himanshu Suri, a local musician he had met on Twitter.

“I turned up with a terrible Queens accent,” said Mr. Ahmed, whose character, Nasir Khan, is the son of a taxi driver in Jackson Heights. Mr. Suri, who was born in that borough to Punjabi parents, offered to show him around, even introducing the actor to his family. “My dad drove a cab, so that kind of made sense,” Mr. Suri said.

In addition to being a first-generation, college-educated South Asian with working-class parents, Mr. Ahmed had something even more specific in common with Mr. Suri: He, too, made wry and politically provocative rap music. With their chemistry and cultural overlap too resonant to ignore, they soon formed a duo, the Swet Shop Boys, uploading four songs online in 2014.

But a funny thing happened before they could release their debut album: Mr. Ahmed, 33, got much more famous as an actor.