This application provides a gear shifting mechanism, a gearbox, and a powertrain. The gear shifting mechanism includes a gear, a gear hub, a one-way clutch, and a sliding apparatus. The gear has a first convex wall and a second convex wall that are disposed around a shaft hole. A first toothed structure is disposed at an end of the first convex wall, and a diameter of the second convex wall is less than that of the first convex wall. The gear hub is sleeved on the second convex wall. The one-way clutch is disposed between the gear hub and the second convex wall. The sliding apparatus is sleeved on the gear hub, and the sliding apparatus is capable of sliding in a direction toward or away from the gear. The gear shifting mechanism can improve stability for transmitting a gear shifting power, thereby improving driving performance of an electric vehicle.