TOKYO, May 26 (AFP) - Japanese police on Friday (May 26) detained a suspect 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 western 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."