Balázs originally conceived the libretto for his roommate Zoltán Kodály in 1908, and wrote it during the following two years. It was first published serially in 1910 with a joint dedication to Kodály and Bartók, and in 1912 appeared with the prologue in the collection "Mysteries". Bartók was motivated to complete the opera in 1911 by the closing date of the Ferenc Erkel Prize competition, for which it was duly entered. A second competition, organised by the music publishers Rózsavölgyi and with a closing date in 1912, encouraged Bartók to make some modifications to the work in order to submit it to the Rózsavölgyi competition.