Equilibrium equations representing a generalization of the corresponding Shafranov-Yurchenko equations are derived for a study of plasma equilibrium and stability in an arbitrarily inhomogeneous magnetic configuration and are solved for one specific case. The stability analysis is performed on the basis of the Mercier criterion. It is shown that, in an approximation linear with respect to ellipticity, the deepening of the magnetic well as a result of plasma displacement can, given an appropriate geometry, outweigh the contribution from ballooning modes. Such geometry is exemplified by the magnetic confinement system Drakon. The improvement in stability is already found in the second-order-pressure approximation (∼β2), whereas in the homogeneous case a similar effect of self-stabilization is observed at higher orders.