CAIRO — Two Italian hostages have been freed from Islamic State captivity in Libya, but two others, who had been captured at the same time, have most likely been killed, Italian officials said on Friday.

In a statement, the Italian Foreign Ministry confirmed the release of Filippo Calcagno and Gino Pollicardo, technicians with Bonatti, an Italian contractor that does engineering and construction work for the oil and gas industries.

They were among four Italians captured in July near an oil and gas plant outside Sabratha, about 50 miles west of Tripoli. The Islamic State has become a domineering presence in Sabratha in recent months. A video that circulated on social media showed the two freed Italians looking exhausted but relieved.

But their joy was tempered by accounts that the bodies of their fellow captives had been discovered at the site of a gunfight between Islamic State fighters and a local militia in Sabratha on Wednesday.