The effect of dexmedetomidine on postoperative agitation of patients with craniocerebral injury was investigated based on magnetic resonance imaging (MRI) with the sparse reconstruction algorithm. Sixty patients with craniocerebral injury who underwent tracheal intubation and craniotomy hematoma removal under general anesthesia in hospital were selected as the research objects. Patients were randomly and averagely divided into the normal saline group (group A) and the dexmedetomidine (DEX) group (group B). DEX was added to patients in group A during anesthesia. Other operations in group B were the same as those in group A, where DEX needed to be used was replaced by an equal amount of the normal saline. All patients received the MRI examination, and the images were processed by using the sparse reconstruction algorithm. After the surgery, some indexes, such as hemodynamics (mean arterial pressure (MAP) and hear rate (HR)), the Riker sedation agitation score, the Ramsay sedation score, and the visual analogue scale (VAS) score were recorded and compared. The results showed that the MRI image quality processed by sparse reconstruction algorithm was observably improved. After reconstruction, the sharpness of the image was significantly improved, and the distinction between lesions and tissues was also increased. The Riker sedation agitation score and the incidence of agitation in group A were greatly lower than those in group B (16% VS 76%, P < 0.05). The Ramsay sedation score of group A was manifestly higher than that of group B. The cases of postoperative nausea, vomiting, chills, delirium, and bradycardia in group A were 2, 1, 1, 0, and 1, respectively. The cases of postoperative nausea, vomiting, chills, delirium, and bradycardia in group B were 3, 9, 6, 5, and 0, respectively. The cases of chills and delirium in group A were observably less than those in group B ( P < 0.05). In conclusion, based on the sparse reconstruction algorithm, the MRI technology and DEX had high adoption value in preventing postoperative agitation of patients with craniocerebral injury. Compared with group B, the hemodynamics of patients in group A was more stable.