When the gunshots rang out, Ali, a 26-year-old Saudi Arabian Shiite Muslim, thought they were fireworks. But when he saw people running, he knew militant Sunnis were attacking his minority community again.

Minutes later, five of his neighbors were dead.

The Oct. 16 shooting was the fourth attack by Islamic State jihadis against Saudi Shiites within 12 months, leaving 40 dead and unnerving a community whose position in an ultra-strict Sunni kingdom has rarely felt so precarious.