Numerical simulation of gas flow in porous media is becoming increasingly attractive due to its importance in shale and natural gas production and carbon dioxide sequestration. In this paper, taking molar densities as the primary unknowns rather than the pressure and molar fractions, we propose an alternative formulation of multicomponent Maxwell–Stefan (MS) model with rock compressibility. Benefiting from the definitions of gas and solid free energies, this MS formulation has a distinct feature that it follows an energy dissipation law, and namely, it is consistent with the second law of thermodynamics. Additionally, the formulation obeys the famous Onsager's reciprocal principle. An efficient energy-stable numerical scheme is constructed using the stabilized energy factorization approach for the Helmholtz free energy density and certain carefully designed formulations involving explicit and implicit mixed treatments for the coupling between molar densities, pressure, and porosity. We rigorously prove that the scheme inherits the energy dissipation law at the discrete level. The fully discrete scheme has the ability to ensure the mass conservation law for each component as well as preserve the Onsager's reciprocal principle. Numerical tests are conducted to verify our theories, and in particular, to demonstrate the good performance of the proposed scheme in energy stability and mass conservation as expected from our theories.