We formulate a nonconservative gravitational theory based on the Herglotz variational principle in a tensorial covariant form. The model presented here may be seen as an improvement of the theory proposed in [ et al., Phys. Rev. D 95, 101501 (2017)], whose resulting field equations are meaningful just in particular coordinate systems. The new theory we report in this work is free from such a restriction. In comparison to the standard general relativity, both theories based on the Herglotz principle contain an extra vector field, the Herglotz field, but the new theory is formulated by taking advantage of the restricted equivalence between Lagrangian functions in the scope of the Herglotz action principle. The more restricted class of equivalent Lagrangian functions, in comparison with the Hamilton variational principle, is the key point to finding a Lagrangian that generates a new alternative gravitational theory in a covariant form. Once the equations that govern the dynamics of the gravitational field are obtained, a few simple cosmological models are investigated. It is found that the Herglotz vector field reduces to a single function that, under certain conditions, plays the role of the cosmological constant in general relativity, turning unnecessary the introduction of dark energy to explain the accelerated expansion of the Universe. The linearized version of the theory is also investigated and it is verified that the theory shows a dissipative character regarding the propagation of gravitational perturbations. From observational data, in both scenarios, the magnitude of the Herglotz field is estimated.