The gentle piano music starts as the doorbell chimes. A white-haired Christian pastor greets his friend, a Muslim imam, and the two converse and laugh over a cup of tea, wincing about their creaky knees as they prepare to part ways. Later, it spurs the same idea in each for a gift: kneepads sent via Amazon Prime. (It is a commercial, after all.)

The piano notes accelerate as the men open their deliveries with smiles, and then each uses the item to kneel in prayer: one at a church, the other at a mosque. The final chords fade.

The ad from Amazon and its message of interfaith harmony became a viral sensation this holiday season, at the end of a year in which talk involving Muslims became particularly ominous. Amazon — which aired the commercial in England, Germany and the United States — cast a practicing vicar and Muslim community leader in the lead roles and consulted with several religious organizations to ensure the ad was accurate and respectful.

“This type of a project is definitely a first for us,” said Rameez Abid, communications director for the social justice branch of the Islamic Circle of North America, one group Amazon worked with. “They were very aware that this was going to cause controversy and might get hate mail and things like that, but they said it’s something that they wanted to do because the message is important.”

A slew of major American brands — including Honey Maid, Microsoft, Chevrolet, YouTube and CoverGirl — prominently featured everyday Muslim men, women and children in their marketing last year. While such ads were apolitical in nature, focused on themes of community and acceptance, they were viewed as bold, even risky, in a year when there were campaign statements by Donald J. Trump about a Muslim registry and a ban on Muslim immigrants.

It was “a glimmer of hope in the midst of a greatly traumatic year for Muslims,” said Mona Haydar, an American poet and activist who appeared in a recent Microsoft commercial with a variety of community leaders, including a transgender teenager and a white policeman.

“For me as a Muslim woman, I represent something right now in the country that for some people incites fear,” said Ms. Haydar, 28, who wears a hijab and hails from Flint, Mich. “This normalizes the narrative that we are just human beings.”

Several advertising executives likened the movement to the decision by mass marketers to cast same-sex couples and their children in ads for the first time in 2013 and 2014, making inclusion and acceptance a priority over potential criticism from some customers.

“With the kind of gay parent issue, we’ve…