Bam Margera was detained by police early yesterday morning outside a biker bar in NYC -- after the "Jackass" star allegedly got into a punching match with a cab driver ... then kicked in his car door.
An eyewitness tells TMZ it all went down outside the famous Hogs & Heifers Saloon. He saw Bam and his friend attack the driver through the car window, so he flagged down cops. We're told Bam walked away ... but the officers caught up to him.
Bam tells a different story. According the him, the cabbie started the whole thing by calling his lady friend a "slut." Bam says the girl spat at the driver, who in turn grabbed her hair. Bam says he then dove into the car and began punching on the guy.
Bam acknowledges the cops showed up "but couldn't figure out who to arrest," so everyone walked away ... free to do it again.