The Israeli army said it prevented a “terror attack against Israeli civilians” and that the gunmen carried an M16 rifle and a handgun.