Let A = (aij) be a matrix-valued Borel mapping on a domain Ω ⊂ ℝd, let b = (bi) be a vector field on Ω, and let LA, bφ = aij∂xi∂xjφ + bi∂xiφ. We study Borel measures μ on Ω that satisfy the elliptic equation L*A, bμ = 0 in the weak sense: ∫ LA, bφ dμ = 0 for all φ ∈ C0∞(Ω). We prove that, under mild conditions, μ has a density. If A is locally uniformly nondegenerate, A ∈ Hlocp, 1 and b ∈ Llocp for some p > d, then this density belongs to Hlocp, 1. Actually, we prove Sobolev regularity for solutions of certain generalized nonlinear elliptic inequalities. Analogous results are obtained in the parabolic case. These results are applied to transition probabilities and invariant measures of diffusion processes.