Spinal cord injury represents a severe form of central nervous system trauma for which effective treatments remain limited. Microglia is the resident immune cells of the central nervous system, play a critical role in spinal cord injury. Previous studies have shown that microglia can promote neuronal survival by phagocytosing dead cells and debris and by releasing neuroprotective and anti-inflammatory factors. However, excessive activation of microglia can lead to persistent inflammation and contribute to the formation of glial scars, which hinder axonal regeneration. Despite this, the precise role and mechanisms of microglia during the acute phase of spinal cord injury remain controversial and poorly understood. To elucidate the role of microglia in spinal cord injury, we employed the colony-stimulating factor 1 receptor inhibitor PLX5622 to deplete microglia. We observed that sustained depletion of microglia resulted in an expansion of the lesion area, downregulation of brain-derived neurotrophic factor, and impaired functional recovery after spinal cord injury. Next, we generated a transgenic mouse line with conditional overexpression of brain-derived neurotrophic factor specifically in microglia. We found that brain-derived neurotrophic factor overexpression in microglia increased angiogenesis and blood flow following spinal cord injury and facilitated the recovery of hindlimb motor function. Additionally, brain-derived neurotrophic factor overexpression in microglia reduced inflammation and neuronal apoptosis during the acute phase of spinal cord injury. Furthermore, through using specific transgenic mouse lines, TMEM119, and the colony-stimulating factor 1 receptor inhibitor PLX73086, we demonstrated that the neuroprotective effects were predominantly due to brain-derived neurotrophic factor overexpression in microglia rather than macrophages. In conclusion, our findings suggest the critical role of microglia in the formation of protective glial scars. Depleting microglia is detrimental to recovery of spinal cord injury, whereas targeting brain-derived neurotrophic factor overexpression in microglia represents a promising and novel therapeutic strategy to enhance motor function recovery in patients with spinal cord injury.