We reexamine the two-dimensional linear O(2) model ($varphi^4$ theory) in the framework of the nonperturbative renormalization-group. From the flow equations obtained in the derivative expansion to second order and with optimization of the infrared regulator, we find a transition between a high-temperature (disordered) phase and a low-temperature phase displaying a line of fixed points and algebraic order. We obtain a picture in agreement with the standard theory of the Kosterlitz-Thouless (KT) transition and reproduce the universal features of the transition. In particular, we find the anomalous dimension $eta(Tkt)simeq 0.24$ and the stiffness jump $rho_s(Tkt^-)simeq 0.64$ at the transition temperature $Tkt$, in very good agreement with the exact results $eta(Tkt)=1/4$ and $rho_s(Tkt^-)=2/pi$, as well as an essential singularity of the correlation length in the high-temperature phase as $Tto Tkt$.