Per Symbols of America:

The idea for Ivory soap came to Harvey Proctor (son of one founder of Proctor & Gamble) during a Sunday morning service in 1879, while the congregation was reading from Psalms 45:8,

All thy garments smell of myrrh, and aloes, and cassia, and out of the ivory palaces whereby they have made thee glad.

James Gamble (son of the other founder) had recently perfected a hard white soap intended to compete with imported castille soaps. Proctor convinced P&G to rename the soap "Ivory," and hired a chemical consultant to analyze the soap for impurities and compare it to three leading castille soaps. The chemist found the Ivory the purest, with only .56% of its weight in impurities, and so Proctor started marketing the soap as 99.44% pure.

In 1881, a batch of the soap was accidentally left in the stirring machine too long, and it dried with a small amount of air inside. As a result, the soap bars floated, and the floating bars were an accidental marketing success.