TORONTO — A shooting in the city of Fredericton early Friday left four people dead, including two police officers, under circumstances that were not yet explained but struck a nerve in a country that has been roiled in recent months by several instances of mass violence.
People in Fredericton, the capital of New Brunswick in the eastern part of the country, said they heard as many as 20 gunshots after a confrontation. Police initially cordoned off a large section of the city with emergency vehicles and ordered residents to remain in their homes and businesses.
Finally, after a tense wait, authorities disclosed the toll: Among the four killed were two officers, a rare case of police killed in the line of duty in Canada. Their names were not released.
Authorities said one suspect was in custody and was being treated for serious injuries. The person’s identity was not announced and no motive was disclosed.
Several other victims were being treated at a regional hospital, but no details about their conditions were immediately available.
‘‘Our hearts are broken by the murder of our two brave police officers,’’ said Mayor Mike O’Brien of Fredericton.
The entire province of New Brunswick had 11 homicides in 2016.
In Fredericton, a city of about 60,000 residents, people said they were stunned by the scene, which occurred as people were heading to work or dropping children at a day care center not far from the apartment complex where the shooting took place.
‘‘This is the first time I’ve even heard of any serious crime or violent crime in this city,’’ said Travis Hrubeniuk, whose fiancee had just left their home when the sirens began.
Bill Henwood, a funeral director at York Funeral Home, whose business is inside the cordoned off area on Brookside Drive, said people sat in their cars or were just standing near the blockade of police and fire vehicles waiting for news.
‘‘It’s not something that we expect in Fredericton to wake up and hear about,’’ Henwood said.
But Canada has had a string of violence, including an instance in Toronto last month in which a man with a handgun opened fire in a crowded part of the city, killing two people and wounding 13 before he either shot himself or was killed by police.
In April, a man who linked himself to a misogynistic online community used a van to run down pedestrians in a busy part of Toronto, killing 10 people and injuring 14.
Authorities are still pursuing leads in an ongoing investigation of a serial killer who has been charged with killing eight men in the city in recent years.
In 2014, a shooting in Moncton, New Brunswick left three Royal Canadian Mounted Police officers dead and two wounded.