We present a virtual element method (VEM) for the equations of magnetohydrodynamics (MHD). These equations describe the evolution of the electric and magnetic fields of a fluid that has a prescribed flow. This method is designed work in very general class of meshes and to preserve the divergence free condition on the magnetic field as dictated by Gauss's law. A sufficient condition for the stability of the method is presented. The construction of the mass matrices is done in the mimetic finite difference (MFD) framework, thus serving as a boundary object to compare and contrast the two frameworks. Finally, we present an experimental study of convergence for three types of meshes: with triangular cells, perturbed quadrilaterals and unstructured polyhedrons that we obtain from Voronoi tessellations.