In 1917 when Carranza was elected president of Mexico, he appointed Pani as head of the Ministry of Industry, Commerce and Labor, and then sent to France as a special envoy during the peace talks resulting in the
Treaty of Versailles in 1918. While Pani was in Europe, the 1920 rebellion by Sonoran revolutionary generals against Carranza, under the
Plan of Agua Prieta, broke out. Pani returned to Mexico and following the election of
Álvaro Obregón as president in 1920, he appointed Pani Secretary of Foreign Affairs in 1921. In 1923 he became the Secretary of the Treasury and Public Credit in 1923, a position in which ratified by President
Plutarco Elías Calles in 1925. For Pani, years between 1923 and 1927 were the apex of his career in government. He oversaw the reorganization of government finance, the re-negotiation of the external debt, and the construction of a single bank under government control, the
Banco de México. His was a program of classical liberalism, "a balanced budget, the restoration of foreign confidence in Mexico's ability to pay debts, and a stable currency." Under Pani, Mexico imposed an income tax, cut salaries of civil servants, and streamlined government by abolishing departments in various ministries. His efforts resulted in greater revenues for government, exceeding expenditures. He strengthened the financial sector for rural areas through the National Bank of Agricultural Credit. His policies resulted in the construction of new infrastructure such as roads, irrigation systems, and major hydraulic works. Pani left the post of Secretary of the Treasury in 1927 and returned to Europe, where he was minister plenipotentiary in France, then Mexican Ambassador to the Spanish Republic. He returned to Mexico during the period when Calles was the power behind the presidency, a period known as the
Maximato (1928–34) to serve as Secretary of the Treasury in 1932 in the government of
Abelardo L. Rodríguez (1932–34). ==Private life and entrepreneurship==