The microgrid concept provides a flexible power supply to the utility where the conventional grid is unable to supply. The microgrid structure is based on renewable energy sources known as distributed generators (DGs) and the power network. Nevertheless, the power quality (PQ) is a great challenge in the microgrid concept. Particularly the inclusion of renewable energy sources into the conventional grids increases the problems in the quality of power, like voltage sag/swell, oscillatory transient, voltage flickering, and voltage notching which reduces the quality and reliability of the power supply. In this paper, a microgrid is considered which consists of PV cells as DG, battery energy storage system (BESS), and a novel control strategy known as the nonlinear autoregressive exogenous model (NARX). The proposed controller is an improved artificial neural network (ANN). The various case studies like sag/swell, unbalanced condition, and voltage deviation have been simulated with the model. The comprehensive simulation results are compared with the proportional-integral (PI) controller. Hence in this paper, the robustness of the proposed controller has been studied through different situations.