Three women were killed and two men were wounded when a gunman opened fire in the Swiss village of Daillon.
The 33-year-old gunman, who has not been named, threatened police when they tried to arrest him and was shot in the chest before being arrested and taken to hospital.
Gun ownership is widespread in Switzerland and voters rejected a proposal in February 2011 to tighten the country's liberal fire arms laws.
The women killed in Daillon were aged 32, 54 and 79. They were all shot at least twice, in the head and chest.
The youngest was married to one of the injured men and they had young children together, regional public prosecutor Catherine Seppey told a news conference.
The injured men were aged 33 and 63.
The gunman was a local resident who had been in psychiatric care in 2005 and was unemployed and living on welfare benefits, police said.
His only previous conviction was for marijuana use.
He used at least two firearms - an old Swiss army carbine and a rifle capable of firing lead shot - even though weapons he had owned had been seized and destroyed in 2005.
He was not currently listed as having any guns.
He began firing from his apartment last night, shooting at people in the street and in neighbouring buildings, but later came out into the street, police said, adding that he appeared to have fired more than 20 shots.
Swiss website 20minutes.ch quoted villagers as saying the gunman had been drinking heavily. It also said he was armed with an assault rifle, but the public prosecutor did not confirm that information.
The village is close to the town of Sion, the capital of the canton - or region - of Valais.
A shooting in the regional parliament in the canton of Zug in 2001 that caused 14 deaths, stirred debate over gun control in Switzerland, where - according to some estimates - at least one in every three of its 8m inhabitants holds a gun.
Many are stored in people's attics, a legacy of Switzerland's policy of creating a citizen army that can be mobilised quickly to defend its neutrality.