Israel evacuated hundreds of families from small towns near the border with the Gaza Strip as Israel and Hamas militants exchanged fire, amid signs of uncertain prospects for a near-term diplomatic solution.

After nearly a month away from home due to the fighting, thousands of Israeli residents living near Gaza had recently returned home, encouraged by a truce with Hamas, the Islamist movement that runs the Palestinian enclave. But...