We present a mathematical description of the voter model dynamics on heterogeneous networks. When the average degree of the graph is $\\\\mu \\\\leq 2$ the system reaches complete order exponentially fast. For $\\\\mu >2$, a finite system falls, before it fully orders, in a quasistationary state in which the average density of active links (links between opposite-state nodes) in surviving runs is constant and equal to $\\\\frac{(\\\\mu-2)}{3(\\\\mu-1)}$, while an infinite large system stays ad infinitum in a partially ordered stationary active state. The mean life time of the quasistationary state is proportional to the mean time to reach the fully ordered state $T$, which scales as $T \\\\sim \\\\frac{(\\\\mu-1) \\\\mu^2 N}{(\\\\mu-2)\\\\,\\\\mu_2}$, where $N$ is the number of nodes of the network, and $\\\\mu_2$ is the second moment of the degree distribution. We find good agreement between these analytical results and numerical simulations on random networks with various degree distributions.