What were gasmasks used for in World War I?

To protect the soldiers against gas attacks. Mustard gas was very nasty and burned the lungs, killing soldiers. After World War 1, the use of poison gas was banned by the Geneva Convention.