Old English ontemn, antefn, "a composition (in prose or verse) sung in alternate parts," from Late Latin antefana, from Greek antiphona "verse response" (see antiphon).
The sense evolved to "a composition (usually from Scripture) set to sacred music" (late 14c.), then "song of praise or gladness" (1590s). It came to be used in reference to the English national song (technically, as OED points out, a hymn) and extended to those of other nations. Modern spelling is from late 16c., perhaps an attempt to make the word look more Greek.