“With the kind of gay parent issue, we’ve gotten a little closer to acceptance, but the Muslim issue in America is still pretty raw for a lot of people,” said Kevin Brady, an executive creative director at the ad agency Droga5, which worked last year with Honey Maid on a commercial about white and Muslim-American neighbors. “I don’t think it should be, but it’s one that I think brands took an extra step of courage to really go out there with in 2016.”

A campaign for YouTube Music in the middle of last year highlighted five individuals, including a young woman in a hijab, rapping to a song by Blackalicious while walking through a school corridor. The inclusion of the ad, “Afsa’s Theme,” was purposeful, said Danielle Tiedt, the chief marketing officer at YouTube, adding that highlighting diversity is “more important than ever.”

“I don’t think diversity is a political statement,” she said. “This is an issue of universal humanity.”

For its ad, Amazon was painstaking in its attention to detail, checking with religious groups about costuming and background imagery, and sending over final proofs of the ad for review, said Mr. Abid and Antonios Kireopoulos, an associate general secretary of the National Council of Churches, another group Amazon consulted.

Ads showing any kind of racial diversity can now attract heaping amounts of vitriol online — most of it delivered anonymously — as State Farm discovered last month when it posted an ad of a black man proposing to a white woman on Twitter. Anti-Muslim remarks, like “they don’t belong here,” peppered the comments under Chevrolet’s video in June of two twins from Los Angeles, named Ruqaya and Qassim, who were accepted into a soccer program the company sponsors. They were 8 years old when the video, which did not mention religion, was made.

Mr. Brady said the agency had prepared Honey Maid for potentially hateful responses to its ad, though it fielded fewer than he feared. (On Facebook, the top comments are appreciative and heartfelt.) Nida’a Moghrabi, a cheesecake seller and mother of three daughters who starred in the commercial with a neighbor she befriended a few years ago, said she had initially been irritated by some rude comments on Facebook and YouTube until she realized how ubiquitous such remarks were.

“If you go to the adoption commercial from Honey Maid, you still see nasty comments,” Ms. Moghrabi said, referring to an ad of a child talking about his new brother. “So I was like, if they’re complaining about adopted kids, of course I’m not going to worry about their comments about me.”