  We study viscosity of the neutron star matter and $r$-mode instability in
rotating neutron stars. Contributions to the shear and bulk viscosities from
various processes are calculated with account of in-medium modifications of the
nucleon-nucleon interaction. A softening of the pion mode and a possibility of
the pion condensation are included. The nucleon pairing is incorporated. In the
shear viscosity we include the lepton contribution calculated with account of
the Landau damping in the photon exchange, the nucleon contribution described
by the medium-modified one pion exchange, and other terms, such as the novel
phonon contribution in the 1S$_0$ superfluid neutron phase, and the neutrino
term in the neutrino opacity region. The nucleon shear viscosity depends on the
density rather moderately and proves to be much less than the lepton term.
Among the terms contributing to the bulk viscosity, the term from the medium
modified Urca reactions possesses strongest density dependence because of the
pion softening. Contributions to the bulk viscosity arising from other
reactions induced by charged weak currents are included. The radiative bulk
viscosity induced by charged and neutral weak currents in the region of the
neutrino transparency of the star is also calculated with account for in-medium
effects. The computed frequency boundary of the $r$-mode stability for the
stars with the mass $\ge 1.8 M_{\odot}$ proves to be above the frequencies of
all rotating young pulsars. To explain the stability of rapid rotation of old
pulsars in X-ray binaries we propose a novel efficient mechanism associated
with appearance of condensates of low-lying modes of bosonic excitations with
finite momentum and/or with an enhancement of the inhomogeneous pion/kaon
condensates in some parts of the star, if the angular velocity exceeds a
critical value.
