Born into the upper middle class, Gómez Pedraza was a student at the time of the Grito de Dolores (Cry of Independence) from Spain in 1810. He enlisted in the royalist army under General Félix María Calleja del Rey and became a lieutenant. He fought the Mexican insurgents during the War of Independence and contributed to the capture of José María Morelos. He was a deputy from New Spain to the Spanish Parliament (the Cortes Generales) in 1820. In 1821, after the fall of the viceregal government, he joined with Agustín de Iturbide, who became a personal friend. Iturbide made him commander of the Mexico City garrison. During the period of the First Mexican Empire under Iturbide (1821–1823), Gómez was an anti-federalist, but after the fall of Iturbide he converted to federalism.