We prove that the space of coinvariants of functions on an affine variety by a Lie algebra of vector fields whose flow generates finitely many leaves is finite-dimensional. Cases of the theorem include Poisson (or more generally Jacobi) varieties with finitely many symplectic leaves under Hamiltonian flow, complete intersections in Calabi-Yau varieties with isolated singularities under the flow of incompressible vector fields, quotients of Calabi-Yau varieties by finite volume-preserving groups under the incompressible vector fields, and arbitrary varieties with isolated singularities under the flow of all vector fields. We compute this quotient explicitly in many of these cases. The proofs involve constructing a natural D-module representing the invariants under the flow of the vector fields, which we prove is holonomic if it has finitely many leaves (and whose holonomicity we study in more detail). We give many counterexamples to naive generalizations of our results. These examples have been a source of motivation for us.