This paper describes a control technique for enhancing the stable operation of distributed generation (DG) units based on renewable energy sources, during islanding and grid-connected modes. The Passivity-based control technique is considered to analyze the dynamic and steady-state behaviors of DG units during integration and power sharing with loads and/or power grid, which is an appropriate tool to analyze and define a stable operating condition for DG units in microgrid technology. The compensation of instantaneous variations in the reference current components of DG units in ac-side, and dc-link voltage variations in dc-side of interfaced converters, are considered properly in the control loop of DG units, which is the main contribution and novelty of this control technique over other control strategies. By using the proposed control technique, DG units can provide the continuous injection of active power from DG sources to the local loads and/or utility grid. Moreover, by setting appropriate reference current components in the control loop of DG units, reactive power and harmonic current components of loads can be supplied during the islanding and grid-connected modes with a fast dynamic response. Simulation results confirm the performance of the control scheme within the microgrid during dynamic and steady-state operating conditions.