Janacek's operatic version was written between 1923 and 1925. He had seen the play early into its run in Prague on December 12, 1922, and immediately saw its potential. He entered into a correspondence with Capek, who was accommodating towards the idea, although legal problems in securing the rights to the play delayed work. When these problems were cleared on September 10, 1923, Janacek began work on the opera straight away. He wrote the libretto himself, and by December 1924 had completed the first draft of the work. He spent another year refining the score, before completing it on December 3, 1925.
The world premiere of the opera was given at the National Theatre in Brno on December 18, 1926, conducted by Frantisek Neumann. It was given in Prague two years later, and in Germany in 1929, but did not become really popular until a production by the Sadler's Wells company in London in 1964.