A musician furious over being thrown out of a rock band extracted bloody revenge in an early morning attack in Brooklyn Monday — using a military-style rifle to fatally shoot three people believed to be bandmates, wound another person and then take his own life, law enforcement sources said.

The triple-homicide took place at 318 Maujer St., a Bushwick building where at least some members of the band are believed to live.

The killer, brandishing a Century Sporter .308-caliber semi-automatic weapon with a 20-round magazine, showed up around midnight and opened fire on a person standing outside.

That person was wounded.

Then he stormed into the building and kept firing off round after round.

Cops said the building was filled with spent shells.

He fatally shot two people on the first floor and one on the third.

The third floor victim was shot in his bed.

The crazed murderer also fired into a first floor bathroom, where a couple was apparently hiding.

They were not injured.

Then he went to the roof of the building and shot himself to death.

The band is made up of Iranians who have been in the country for a while and were seeking asylum here, law enforcement sources.

A neighbor, who identified himself only as Frank, said the building has been hosting boisterous parties.

“During the summer it was ongoing, really loud parties with the street blocked off by gypsy cabs,’’ he said.

“It was the usual hipster rave scene.’’

Frank said there are several other party houses in the area.

He described “huge blowout mega party — there must have been as many as 1,000 people” and a DJ on the roof of another area neighborhood building.

That party happened in late summer, he said.

Adding to the chaos in the neighborhood, another man was shot in the leg a few blocks away. He was taken to Bellevue Hospital.

The two shootings were apparently unrelated, cops said.

Additional reporting by Amanda Lozada