Japanese police on Friday detained a man who had holed up in a building after allegedly killing four people, including two police officers, in a gun and knife attack.
Masanori Aoki, 31, was taken into custody at his house outside a farm near the city of Nakano in the Nagano region, police said.
They also confirmed a fourth fatality overnight -- an elderly woman who was found injured at the scene and later pronounced dead.
Another woman and two police officers were earlier confirmed dead in the attack.
Aoki has initially been formally arrested with suspicion of murder over the death of one of the police officers, Nagano regional police chief Iwao Koyama told reporters.
He is likely to be rearrested later in connection with the other deaths, in a process that allows law enforcement to detain a suspect for longer while investigations continue.
Aoki is not contesting the charge, Koyama said, adding 100 officers are investigating the case.
"This case was an extremely heinous act that shocked not just regional residents but society as a whole," he said.
"We need to thoroughly investigate this and see the whole picture including the how and why," he said.
The rampage in a rural area of the central region was a rare instance of violent crime in Japan, which has a low murder rate and some of the world's toughest gun laws.
Several local media reported Aoki is the son of the speaker of Nakano's city assembly, and lived with his parents and aunt in the house where he holed up overnight.
"We pray for the souls of the deceased and express our heartfelt condolences to the bereaved families," top government spokesman Hirokazu Matsuno told reporters.
"Police are investigating to uncover the whole picture of the incident, including how the crime developed and its background."
'Because I wanted to'
The attack started on Thursday afternoon, when a local man working on a farm saw a woman "running from the road saying, 'help me'," he told national broadcaster NHK.
"Behind her came a man wearing camouflage and carrying a large knife, who stabbed her in the back," the 72-year-old witness said.
He said he called emergency services while neighbours tried to resuscitate the woman.
The attacker announced: "I killed her because I wanted to," according to an eyewitness cited by Kyodo news.
Local media said he then fired what has been described as a hunting gun at police officers who arrived at the scene.
The officers were inside a patrol car when the attacker placed the weapon against a window of the vehicle and fired twice, NHK reported.
The slain officers were identified as Yoshiki Tamai, 46, and Takuo Ikeuchi, 61.
The man then barricaded himself inside the house, with his mother and aunt also on the premises, local media said.
He remained most of the night, with occasional gunshots heard, while the two women managed to escape on their own.
With few instances of major violent crime, Japan was left reeling in July last year when former prime minister Shinzo Abe was shot dead in broad daylight with an apparently homemade gun.
Abe's accused assassin, Tetsuya Yamagami, reportedly targeted the politician over his links to the Unification Church.
And last month, a man was arrested for allegedly hurling a pipe bomb-like explosive towards Prime Minister Fumio Kishida as he campaigned in the western city of Wakayama.
Kishida was unharmed and a man arrested on the scene will undergo a three-month psychiatric examination, a regional court said this week.
The suspect has reportedly remained tight-lipped about his motive for that failed attack.