Traditional power flow algorithms have been widely used for evaluating voltage and frequency stability of microgrids. However, few research papers are found within the context of harmonic analysis and the impact of power quality degradation in the microgrids stability. This paper presents a novel approach for the voltage stability assessment and harmonic analysis in microgrids based on the formulation of an optimal power flow model. In the proposed approach, the objective function determines the maximum loadability factor of the network considering limits for the total harmonic distortion, voltage magnitudes and system frequency. The optimization problem is solved by interior-point method. Simulations are carried out using the IEEE 33-bus test system, modified in order to include distributed generators connected to the grid considering VSI (Voltage Source Inverters) with their frequency droop characteristics. Computational tests are performed considering microgrids in grid-connected and islanded operation modes. Results are validated based on a comparative analysis with the RSCAD (Real-Time Simulation Software Package) software to prove the effectiveness of the proposed formulation.