We find modular transformations of normalized characters for the following W-algebras: (a) W-k(min)(g), where g = D-n (n >= 4),or E-6,E-7,E-8, and k is a negative integer >= -2, or >= -h(boolean OR)/(6)-1, respectively; (b) quantum Hamiltonian reduction of the g-module L(k Lambda(0)), where g is a simple Lie algebra, f is its non-zero nilpotent element, and k is a principal admissible level with the denominator u > theta(x), where 2x is the Dynkin characteristic of f, and theta is the highest root of g. We prove that these vertex algebras are modular invariant. A conformal vertex algebra V is called modular invariant if its character trVq(0)(L)-c/24 converges to a holomorphic modular function in the complex upper half-plane on a congruence subgroup. We find explicit formulas for their characters. Modular invariance of V is important since, in particular, conjecturally it implies that V is simple, and that V is rational, provided that it is lisse.