Capillary imbibition of a wetting fluid in a porous medium is studied. A method of constructing the exact solution of the corresponding problem is developed. An iteration procedure is developed for the case of countercurrent capillary imbibition. The salient features of the flow generated by capillary forces are revealed on the basis of numerical results.