First came the crackle of automatic gunfire, then a siren blasted out over the desert air alerting the hundreds of workers at the sprawling natural gas complex in eastern Algeria that something was badly wrong.

In the chaos, AK-47-wielding militants – some bearded; others clean-shaven – began to round up workers,...