BMX bike legend Dave Mirra -- who once had the record for the most X Games medals -- has died of an apparent suicide ... TMZ Sports has learned.

Cops say the 41 year old's body was found in his truck in Greenville, North Carolina Thursday with an apparent self-inflicted gunshot wound to the head.

We're told he had been in the area visiting with friends.

Mirra leaves a wife and two kids.

Officials tell TMZ Sports cops are investigating the death.

Earlier Thursday, a photo of Mirra and his wife together appeared on Dave's Instagram account with the caption, "My Rock! Thank god."

Mirra hosted 2 seasons of 'Real World/Road Rules Challenge' on MTV -- and was the namesake of several BMX video games.

Mirra also drove for Subaru rally car racing team.