We develop a new method to invert the target profiles of radial distribution functions (RDFs) to the pair forces between particles. The target profiles of RDFs can be obtained from all-atom molecular dynamics (MD) simulations or experiments and the inverted pair forces can be used in molecular simulations at a coarse-grained (CG) scale. Our method is based on a variational principle that determines the mean forces between CG sites after integrating out the unwanted degrees of freedom. The solution of this variational principle has been shown to correspond to the Yvon-Born-Green (YBG) equation [Noid, J. Phys. Chem. B 111, 4116 (2007)]. To invert RDFs, we solve the YBG equation iteratively by running a CG MD simulation at each step of iteration. A novelty of the iterative-YBG method is that during iteration, CG forces are updated according to the YBG equation without imposing any approximation as is required by other methods. As a result, only three to ten iterations are required to achieve convergence for all cases tested in this work. Furthermore, we show that not only are the target RDFs reproduced by the iterative solution; the profiles of the three-body correlation function in the YBG equation computed from all-atom and CG simulations also have a better agreement. The iterative-YBG method is applied to compute the CG forces of four molecular liquids to illustrate its efficiency and robustness: water, ethane, ethanol, and a water/methanol mixture. Using the resulting CG forces, all of the target RDFs observed in all-atom MD simulations are reproduced. We also show that the iterative-YBG method can be applied with a virial constraint to expand the representability of a CG force field. The iterative-YBG method thus provides a general and robust framework for computing CG forces from RDFs and could be systematically generalized to go beyond pairwise forces and to include higher-body interactions in a CG force field by applying the aforementioned variational principle to derive the corresponding YBG equation for iterative solution.