A pipeline explosion has stopped flows from Libya’s largest oil field, the nation’s oil company said Saturday, warning it may have to stop all of its operations if attacks continue.

The blast came after gunmen assaulted a U.S.-Libyan oil field Friday and less than two weeks after gunmen claiming to represent Islamic State killed nine guards and kidnapped at least three workers at a nearby Libyan-French facility.

The...