Antonio López de Santa Anna announced a competition to write a national anthem for Mexico. The competition offered a prize for the best poetic composition representing patriotic ideals. Francisco González Bocanegra, a talented
poet, was not interested in participating in the competition. He argued that writing love poems involved very different skills from the ones required to write a national anthem. His fiancée,
Guadalupe González del Pino (or Pili), had undaunted faith in her fiancé's poetic skills and was displeased with his constant refusal to participate in spite of her constant prodding and requests from their friends. Finally she decided to take matters into her own hands. Under false pretenses, she lured him to a secluded bedroom in her parents' house, locked him into the room, and refused to let him out until he produced an entry for the competition. Inside the room in which he was temporarily imprisoned were pictures depicting various events in
Mexican history which helped to inspire his work. After four hours of fluent (albeit forced) inspiration, Francisco regained his freedom by slipping all ten verses of his creation under the door. After Francisco received approval from his fiancée and her father, he submitted the poem and won the competition by unanimous vote.
 González was announced the winner in the publication
Official Journal of the Federation (DOF) on
At the same time the lyrics were chosen, a set of music was chosen. The winner was
Juan Bottesini, but his entry was disliked due to aesthetics. This rejection caused a second national contest to find music for the lyrics.
 At the end of the second contest, the music that was chosen for González's lyrics was composed by Jaime Nunó, a
Spanish-born band leader. At the time of the second anthem competition, Nunó was the leader of several Mexican military bands. He had been invited to direct these bands by President
Santa Anna, whom he had met in
Cuba. About the time that Nunó first came to Mexico to start performing with the bands, Santa Anna was making his announcement about creating a national anthem for Mexico. Out of the few musical compositions submitted, Nunó's music, titled "God and Freedom" (Dios y libertad), was chosen as the winner on
 The anthem was officially adopted on
September 16 of that same year. The inaugural interpretation was directed by Juan Bottesini, sung by
Claudia Florenti and
Lorenzo Salvi at the
Santa Anna Theatre (now known as the National Theatre of Mexico).