The Espionage Act was passed by Congress in 1917 during World War I to prohibit interference with military operations, support of enemies during wartime, and promote loyalty to the United States. It allowed for prosecution of individuals who engaged in spying, sabotage, or other activities that could hinder the war effort.