Masked gunman stormed into the home where the hip hop duo Rae Sremmurd were staying, assaulted a security guard, and made off with a safe ... TMZ has learned.

Law enforcement sources tell us ... 4 armed robbers knocked on the door of the San Fernando Valley home at 4:30 AM Saturday. We're told a security guard answered, got pistol-whipped ... and the crooks entered.

Our sources say the men, wearing ski masks, demanded to be taken to the safe in the house ... stole the entire thing and fled. It's unclear at this time what's inside. Slim Jxmmi was home at the time of the break in, but Swae Lee was not. 

We're told Swae and Jxmmi are staying at the pad, which doubles as a recording studio  Cops are investigating.

The home invasion comes after a busy couple weeks for robbers and thieves in the same areaWiz KhalifaBella ThorneChristina MilianYasiel Puig and John Mayer have all been victims of burglaries or attempted burglaries.

It's been a rough week for Rae Sremmurd ... especially Swae Lee. As we reported, he was hit in the face while on stage at a concert last Sunday when a fan threw her cell phone at him. Swae's mouth was bleeding, and he indicated his tooth got busted. He was unhappy to say the least.