In the context of integrating Renewable Energy Sources, Microgrid (MG) development is pivotal, particularly as a foundational technology for Smart-Grid evolution. Despite advancements in control techniques, challenges persist in ensuring system stability and accurate power sharing across diverse operational conditions and load types. The objective of this research is to control numerous paralleled inverters-based distributed generators (DGs) that contribute to power sharing in an island MG. The proposed methodology involves developing an innovative small-signal model for islanding MGs that incorporate virtual impedances. Subsequently, optimization algorithms based on Genetic Algorithm (GA) and Particle Swarm Optimization (PSO) are proposed and compared for designing the virtual impedances. These algorithms analyze all potential operating points, aiming to minimize reactive power mismatches while maximizing MG stability. The suggested objective function facilitates the simultaneous achievement of these objectives. The proposed approaches were tested using MATLAB-Simulink software, and the comparison of the results between conventional approach and the proposed optimal approaches shows significant improvement in terms of the dynamic response during load changes, such as a decrease in response time by up to 20%, a reduction in overshoot percentage by approximately 15%, and a settling time improvement of nearly 25%. These quantified improvements highlight the effectiveness of the GA and PSO methods in minimizing the reactive power-sharing error while optimizing MG performance and stability.