" the starter began cranking even though the key "
The key has nothing to do w/ the starter engaging. It provides current to the ignition circuit, not the starting circuit. Unless you've got it wired wrong.......
You've got a loose connection/bad cable.
Find it as Tom said.
Next, Google "wiring diagrams JMOR" and find the diagram that fits your tractor & alternator. Wire that wrong & you will burn up the alternator.