Getty
Exclusive

Slim 400 Target of Attack by Masked Gunmen ... Drive-By AND Ambush

Slim 400 got shot at by gunmen in a passing vehicle, but then the masked attackers hopped out to try to finish the job ... TMZ has learned.

Sources close to the rapper tell us ... Slim was on the phone with his Ice Watar label business partner, Mud Dollaz, Friday night in Compton when the shooting occurred. 

We're told Mud called Slim to check in because he was waiting for him at the studio, and the last thing he heard the rapper say was "oh sh*t."

After that, our sources say Dollaz heard a series of gunshots for several seconds ... and then a female voice screaming for Slim to keep his head up, so he knew he'd been hit.

Eyewitnesses on the scene tell us the people who shot at the rapper drove by in a black vehicle spraying bullets, but then actually stopped and jumped out to shoot more at 400 before getting back in to drive away. We're told they were wearing masks.

Our sources say Slim frequently hangs out with friends on the particular block where he was shot.

We broke the story ... Slim 400 was shot around 8:30 PM Friday night and suffered multiple gunshot wounds. We later learned he took 9 bullets to his body ... to his upper and lower back, his jaw and the top of his head. He's in stable condition following surgery, and miraculously -- is expected to make a full recovery in coming weeks.

TMZ.com

We also spoke to Slim's friend, YG, at LAX Monday ... he confirmed the "Bruisin" rapper's on the up-and-up, and vowed to "stay dangerous" in face of the incident.

Click here for info about our online advertising practices.