Born in Abiquiú, in what is now Rio Arriba County, New Mexico, Gallegos attended parochial schools. He studied theology at the Jesuit run College of Durango (Colegio de Durango), Republic of Mexico, graduated in 1840, and was ordained a Roman Catholic priest. He served as member of the legislative assembly of what was then the Department of New Mexico, Republic of Mexico from 1843 to 1846. He served as member of the first territorial council of the Territory of New Mexico in 1851.
Gallegos was elected as a Democrat to the Thirty-third US Congress (March 4, 1853 – March 3, 1855). He was elected to a second term but served only briefly, March 4, 1855, to July 23, 1856, as he was succeeded by Miguel Antonio Otero (I), who had successfully contested Gallegos's election. He served as member of the territorial house of representatives 1860-1862 and served as speaker. He was an unsuccessful candidate for election in 1862 to the Thirty-eighth US Congress.
In 1862, Gallegos was made a prisoner of war by the Texas Confederate troops when they came through Santa Fe. He served as Treasurer of the New Mexico Territory in 1865 and 1866, and as Superintendent of Indian Affairs in New Mexico in 1868.
Gallegos was elected as a Democrat to the Forty-second US Congress (March 4, 1871 – March 3, 1873). He was an unsuccessful candidate for reelection in 1872 to the Forty-third US Congress. He died in Santa Fe, and was interred there in the Catholic Cemetery.