Nik Richie -- the guy behind TheDirty.com -- was detained by police last weekend after K.O.ing some dude in a bar fight in Pittsburgh ... but according to Nik, it was all in self-defense.
Sources close to the fight tell TMZ ... Richie -- who's married to former "Bachelor" winner Shayne Lamas -- was leaving the bathroom at McFadden's Bar when some random dude recognized him, started talking trash ... and then shoved him.
We're told the guy made another aggressive move toward Nik -- so Richie socked the guy in the face ... knocking him to the ground.
Cops quickly arrived to the scene and placed both men in handcuffs ... but Richie was eventually released after the situation was defused.
We're told Richie does not plan to press any charges over the incident.