A gearbox for a self-propelled machine includes primary and secondary shafts, each having a respective gear train aligned with one another around the shaft. Each gear of the gear train of the primary shaft permanently meshes with a respective gear of the secondary shaft. A gearing mechanism includes a driving member meshing with a driven member for being coupled to/decoupled from the primary shaft by a clutch mechanism. At least one key is engaged selectively with a gear carried by the secondary shaft. The secondary shaft includes two half-shafts mounted freely rotatable relative to each other and aligned by a sleeve inside which one end of each half-shaft is received. The sleeve has at least one longitudinal guide path along which the key, constrained to rotate with the sleeve, is mounted to move axially, this key-holder sleeve being coupled to each of the half-shafts via a respective declutchable coupling.