Let 2 ≤ n ≤ 4. We show that for an arbitrary measure μ with even continuous density in R n and any origin-symmetric convex body K in R n ,where ξ ⊥ is the central hyperplane in R n perpendicular to ξ , and |B n 2 | is the volume of the unit Euclidean ball in R n . This inequality is sharp, and it generalizes the hyperplane inequality in dimensions up to four to the setting of arbitrary measures in place of volume. In order to prove this inequality, we first establish stability in the affirmative case of the Busemann-Petty problem for arbitrary measures in the following sense: if ε > 0, K and L are origin-symmetric convex bodies in R n , n ≤ 4, and μ K ∩ ξ ⊥ ≤ μ L ∩ ξ ⊥ + ε, ∀ξ ∈ S n−1 , then μ(K) ≤ μ(L) + n n − 1 |B n 2 | n−1 n |B n−1 2 | Vol n (K) 1/n ε.