Complex sentence: During the Spanish Civil War he became mayor of Figueres by chance, and while serving in this office he tried to keep the peace, and prevent looting and political witch hunts.
Split into simpler sentences: During the Spanish Civil War, he became mayor of Figueres by chance. As mayor he tried to keep the peace, prevent looting and political witch hunts.