In this paper, optimal controller design of the nonlinear model of an autonomous inverter-based microgrid has been used. The controller is optimized to reject the high frequency disturbances and damp the output LC filter to avoid resonance with the external network. The control problem has been formulated as optimization problem. The optimal controller parameters have been obtained by using the particle swarm optimization (PSO). This is done based on minimization of the error in the measured power. Finally, the nonlinear time domain simulation has been carried out to assess the effectiveness of the proposed controller under different disturbances and loading conditions.