The current-controlled grid-connected inverter with LCL filter is widely used in the distributed generation system (DGS), due to its fast dynamic response and better power quality features. However, with the increase of power injected into the grid, control performances of the inverter will be significantly influenced by the nonideal grid conditions. Specifically, the possible wide variation of the grid impedance challenges the system stability. Meanwhile, background harmonics of the grid can greatly distort the injected current. Therefore, the control of the inverter should be designed with strong stability-robustness and high harmonic-rejection-ability, both of which correlate closely with the inverter output impedance. However, it is difficult to shape the output impedance into the one with a desirable characteristic simply by adjusting the current loop gain. In this paper, an impedance shaping method is proposed with virtual impedances, and the current control loop can be designed independently. The implementation and parameter design of the virtual impedances are studied under the practical considerations. With this proposed method, the grid-connected inverter can work stably over a wide range of the typical inductive-resistive grid impedance and exhibit strong rejection ability of grid-voltage harmonics. Experimental results from a 6-kW single-phase grid-connected inverter confirm the effectiveness of the proposed method.