KAMAISHI, Japan—After the devastating earthquake and tsunami struck northeastern Japan this year, the country's Self Defense Forces reinforced local police, firefighters and government officials by distributing supplies, searching for bodies and clearing the debris.

Now Japan's soldiers have another job: fighting swarms of flies that are spreading in the sweltering summer heat. In a first-of-its-kind mission for the Japanese military, soldiers are spraying down piles of rubble with insecticide, while...