The widespread popularity of renewable and sustainable sources of energy such as solar and wind calls for the integration of renewable energy sources into electrical power grids for sustainable development. Microgrids minimize power quality issues in the main grid by linking with an active filter and furnishing reactive power compensation, harmonic mitigation, and load balancing at the point of common coupling. The reliability issues faced by standalone DC microgrids can be managed by interlinking microgrids with a power grid. An artificial intelligence-based Icosϕ control algorithm for power sharing and power quality improvement in smart microgrid systems is proposed here to render grid-integrated power systems more intelligent. The proposed controller considers various uncertainties caused by load variations, state of charge of the battery of microgrids, and power tariff based on the availability of power in microgrids. This paper presents a detailed analysis of the integration of wind and solar microgrids with the grid for dynamic power flow management in order to improve the power quality and to reduce the burden, thereby strengthening the central grid. A smart grid system with multiple smart microgrids coupled with a renewable energy source with tariff control and judicious power flow management was simulated for power-sharing and power quality improvement. A hardware prototype of the artificial intelligence-based Icosϕ control algorithm with nonlinear load was also implemented successfully. Furthermore, the economic viability was investigated to ensure the feasibility of the smart microgrid system with the proposed controller design for power flow management and power quality improvement.