We present a next-to-leading-order calculation of the production of a Z boson with two jets, one or more of which contains a heavy quark (Q=c,b). We show that the cross section with only one heavy-quark jet is larger than that with two heavy-quark jets at both the Fermilab Tevatron and the CERN LHC. These processes are the dominant irreducible backgrounds to a Higgs boson produced in association with a Z boson, followed by h->bb. Our calculation makes use of a heavy-quark distribution function, which resums collinear logarithms and makes the next-to-leading-order calculation tractable.