I know that after Emperor Severus Alexander was killed by his own men the Roman empire was chaotic for 50 years. Then Diocletian came and restored order but I don't really understand what happened during the crisis and how Diocletian restored order without losing it.
It's hard to describe the crisis without going into the weeds. There were just so many rebellions, invasions, and minor officials declaring themselves Augustus. And the details of these are exactly what makes up the crisis.
But I'll try and give a 40,000' overview, largely by using the reign of Gallienus.
So in 235 Severus Alexander (the 26th emperor) died. And the empire immediately went into a series of civil wars. In 253 when Valarian ascended the purple he was the 40th official emperor. In the prior 18 years there had been 13 official emperors, and dozens of unofficial pretenders. Many of these pretenders were military commanders in charge of border provinces. So when they marched on Rome or another emperor they tended to leave the borders undefended.
How Valerian became emperor is a great example. In 253 Trebonianus Gallus was emperor, and had to put down Aemilianus. Gallus was killed before Valerian could get to Italy. So Valerian's troops proclaimed him emperor and continued the march. He beat Aemilianus and was accepted by the Senate.
Immediately Valerian went off to try and stabilize the East. The Sassanids had occupied Antioch and Goths were raiding Asia Minor. He left his son, Gallienus, to hold down the west. Well things went badly and within a half dozen years Gallienus became emperor.
Gallienus had spent his father's reign fighting on the frontier, as both the Germans and the Goths smelled blood in the water and stepped up raids. This led to Ingenuus to feel that Pannonia was too put upon, so declared himself emperor. Gallienus marched to the Danube to put down Ingenuus, leaving the Rhine under-garrisoned. So the Alemanni poured over and invaded Italy while the Franks attacked and raided as far as Spain. Gallienus marched back and caught and defeated first the Franks then the Alemanni.
About that same time Regalianus declared himself emperor and took control of much of the Balkans. Shortly after an army of Sarmatians crossed the Danube. They ran into Regalianus and killed him. Gallienus who was marching on Regalianus, ran into the Sarmatians and drove them back beyond the Danube.
All this before Valerian died and Gallienus even became emperor.
With Valerian's death Macrianus (an eastern general) and his sons declared themselves emperors and invaded the Balkans. Gallienus had to send a subordinate to defend against that because Postumus had declared himself emperor with the support of Britain, Gaul, and Spain. He also basically granted the East to Odenathus, with he unspoken agreement that if Odenathus could hold it Gallienus wouldn't challenge it. This marked the start of the independent kingdom of Palmyra, under the polite fiction that Odenathus was acting under Gallienus' authority.
Gallienus marched West on Postumus but was unable to bring him to heel. And that was interrupted by Aemilianus the former prefect of Egypt who rebelled and had to be put down.
Around the same time the Goths started acting up again and built naval flotillas that ranged up and down the Aegean, going so far as sacking Athens. So Gallienus had to go back to the Balkans to fight the Goths again.
Then his lieutenant in the West, Aureolus declared himself emperor... so now Gallienus had to take care of the guy who was supposed to be taking care of the still independent Postumus.
At this point Gallienus' troops were getting tired of the constant fighting and a conspiracy formed that successfully killed him.
That's the barest overview of a single guy over about a dozen years. The whole crisis period reads like this. Constant rebellion, constant invasion, and frequent plague (I left out the plague). Basically anything that could go wrong, did go wrong for about 50 years.
This continued until Diocletian. So what did he do? First of all he won his battles, putting down both the rebels who popped up and defending the borders. This took a long time. And it was years before the empire was reunited. One of Diocletian's biggest accomplishments was surviving long enough to do it.
Second he raised competent men to be co-emperors with him. The empire had been unofficially divided since at least Gallienus. The local areas needed local rule. So Diocletian replaced things like the Gaullic Empire with the Tetrarchy. He basically suborned some of his biggest rivals and put them to work for him.
It should be pointed out though, that while Diocletian held the empire together with sheer force of will, his solutions didn't survive him. The empire was back to civil war before he died. Had Constantine not been able to win that, it's possible that we might now view Diocletian as simply a temporary stability. It's the (almost) back to back reigns of Diocletian and Constantine that really brought the empire back to stability.