We compute the beta functions for the three gauge couplings and the Yukawa matrices of a general two-Higgs-doublet model in the modified minimal subtraction scheme to three loops. The calculations are performed using Lorenz gauge in the unbroken phase. We discuss in detail the occurrence of poles in anomalous dimensions and propose practical prescriptions to avoid them. We provide explicit results for the often used Z2-symmetric versions of the two-Higgs-doublet model of types I, II, X, and Y. Furthermore, we provide the first independent cross-check of the three-loop Yukawa coupling beta functions of the Standard Model.