“I was very wary of writing a song that felt like homework,” Mr. Miranda said over the phone on Wednesday from the “Sesame Street” offices in New York, where he was recording another number for disaster relief. “I wanted to write a danceable tune that is just everywhere, and by being everywhere, is doing good.”

“There’s no favor I haven’t called in, no avenue I’m not traveling for Puerto Rico,” he added. “I’ll go wherever for help and awareness.”

On his lively Twitter feed, Mr. Miranda has rallied others to do the same, helping to raise nearly $3 million (before the song’s release) in collaboration with MoveOn.org and the Hispanic Federation, where his father, Luis Miranda Jr., was the founding president.

While working on “Almost Like Praying,” the musician also jumped into the political fray, going after President Trump after Mr. Trump tweeted on Saturday morning that Puerto Ricans “want everything to be done for them” in the recovery effort. Mr. Miranda countered, “You’re going straight to hell.”