We consider a generalization of Riemannian geometry that naturally arises in the framework of control theory. Let $X$ and $Y$ be two smooth vector fields on a two-dimensional manifold $M$. If $X$ and $Y$ are everywhere linearly independent, then they define a classical Riemannian metric on $M$ (the metric for which they are orthonormal) and they give to $M$ the structure of metric space. If $X$ and $Y$ become linearly dependent somewhere on $M$, then the corresponding Riemannian metric has singularities, but under generic conditions the metric structure is still well defined. Metric structures that can be defined locally in this way are called almost-Riemannian structures. They are special cases of rank-varying sub-Riemannian structures, which are naturally defined in terms of submodules of the space of smooth vector fields on $M$. Almost-Riemannian structures show interesting phenomena, in particular for what concerns the relation between curvature, presence of conjugate points, and topology of the manifold. The main result of the paper is a generalization to almost-Riemannian structures of the Gauss-Bonnet formula.