TORONTO — The Canadian police have charged a 48-year-old man in the fatal shootings of two officers and two civilians in New Brunswick, an attack that struck a nerve in a country hit by several instances of mass violence over the past few months.

The police in Fredericton, a university town in New Brunswick, said that the man, Matthew Vincent Raymond, had been arrested and charged with four counts of first-degree murder. He is due to appear in court on Aug. 27.

The victims in the shooting on Friday were identified as Constable Robb Costello, 45; Constable Sara Burns, 43; Donnie Robichaud, 42; and Bobbie-Lee Wright, 32.

The two officers were responding to a report of gunshots in a residential area of Fredericton, the provincial capital, when they came upon two bodies, Deputy Police Chief Martin Gaudet said at a news conference on Friday. The officers were killed as they approached the two civilian victims, he said.