In this paper, we propose an algorithm that integrates a dynamic leader election (DLE) mechanism and model-free reinforcement learning (RL). The algorithm aims to address the issue of fixed leaders restricting reactive power flow between buses during heavy load variations in islanded microgrids, while also overcoming the challenge of obtaining model parameters such as resistance and inductance in practical microgrids. The proposed method consists of two main components: a dynamic leader election algorithm and a model-free reinforcement learning algorithm. First, we establish a voltage containment control and reactive power error model for alternating current (AC) microgrids and construct a corresponding value function based on this error model. Second, a dynamic leader election algorithm is designed to address the issue of fixed leaders restricting reactive power flow between buses due to preset voltage limits under unknown or heavy load conditions. The algorithm adaptively selects leaders based on bus load conditions, allowing the voltage limits to adjust accordingly, thereby regulating reactive power flow between buses. Then, to address the difficulty of accurately acquiring parameters such as resistance and inductance in microgrid lines, a model-free reinforcement learning method is introduced. By constructing a value function based on voltage and reactive power errors, this method relies solely on real-time measurements of voltage and reactive power data, without requiring specific model parameters, to realize accurate reactive power sharing and voltage containment control. Ultimately, simulation experiments on AC microgrids are conducted to validate the effectiveness of the proposed algorithm.