Microgrid (MG) control in off-grid mode of operation is one of the main challenges in MGs. Under different loading conditions, voltage and frequency deviate from their nominal limits. The droop control method that applied with the current control and voltage control loops can restore the MG voltage and frequency to their nominal limits. However, it can’t regulate these parameters to their specified values. Additionally, the droop control method can’t do well when the system supplies either nonlinear or unbalanced loads. This paper proposes a control technique for adjusting the voltage and frequency of an MG in islanded mode under different loading conditions. The proposed method is based on applying the H-infinity ($$H\infty$$) robust control as a secondary controller with the droop control method to improve its performance. The proposed method is composed of four stages including; droop control loop, voltage control loop, current control loop and control loop for inductance–capacitance–inductance (LCL) filter and coupling circuit. $$H\infty$$ control has an internal model that can control the frequency and improve the system power quality by decreasing the disturbance frequencies. Moreover, it has two weighted parameters $$\xi$$ and $$\mu$$ that must be correctly adjusted to improve the stability of the system. For a proper adjusting of these parameters, the Harmony Search (HS) optimization method is applied. To prove the effectiveness and superiority of the proposed method, it is applied on a test system with three different loading scenarios using MATLAB/Simulink program. The results are compared with those of droop controller and they confirm that the proposed control method is more effective in controlling the microgrids under islanded mode operation.