From the Wikipedia:
The Pledge of Allegiance was written in August 1892 by Francis Bellamy (1855–1931), who was a Baptist minister, a Christian socialist, and the cousin of socialist utopian novelist Edward Bellamy (1850–1898). The original “Pledge of Allegiance” was published in the September 8 issue of the popular children’s magazine The Youth’s Companion as part of the National Public-School Celebration of Columbus Day, a celebration of the 400th anniversary of Christopher Columbus’s arrival in the Americas.
Initially, it went like this: “I pledge allegiance to my Flag and the Republic for which it stands, one nation indivisible, with liberty and justice for all.”