Abbas Sahraei, the 26-year-old criminal, entered two houses in Arak and shot 8 people with a Kalashnikov, killing 5 of them instantly, ISNA quoted the city’s prosecutor as saying.
A sixth victim later died in hospital and another was in critical condition, he added.
The first house targeted was the home of a police officer who had arrested the man last year on charges of complicity in a murder.
The officer, his sister, mother and brother were all killed while another family member was hospitalised.
The suspect then went to the house of the victim who he and two others are accused of killing last year and shot dead his parents. Their son was also injured.
These people had testified against the murderer in a trial.
The shooter managed to escape, but his brother, who allegedly accompanied him in the rampage, was arrested, the prosecutor said.
A few hours later, the gunman was also arrested in Arak when he was preparing money to flee to Tehran. He reportedly was not carrying any gun when detained.
The gunman had been released on bail of two billion rials ($50,000) on January 1, AFP reported.
Gun violence is rare in the Islamic Republic and offenders face severe punishment.