(CNN) -- A nearly five-hour manhunt across Seattle ended Wednesday afternoon when the suspect in a pair of fatal shootings turned a gun on himself as police closed in, investigators said.
Detectives believe the man was behind both the triple slaying at a coffeehouse in the city's University District and the fatal shooting of a woman near downtown about a half-hour later, Assistant Police Chief Jim Pugel told reporters. The suspect shot himself in the head but was still alive Wednesday evening, police said.
Two men were found dead at the coffeehouse, and a woman wounded in the shooting spree died in a hospital later. Two other men were listed in critical condition Wednesday afternoon.
The second shooting left one woman dead in what police described as a possible carjacking about four miles away. Detectives "feel very confident that unfortunately, these are all connected, but fortunately we have the person in custody," Pugel said.
He said a plainclothes detective spotted the suspect in southwest Seattle, within two miles of where the sport-utility vehicle seen fleeing the second shooting had been ditched. The detective called in uniformed officers, and the man shot himself as they approached, Pugel said.
Barely an hour earlier, police had released security-camera images of the yet-unidentified suspect at Café Racer, in the city's University District. Heavily armed police were used dogs to search the neighborhood around the cafe for much of Wednesday afternoon, neighbors said.
"The streets are blocked off, and there's tons of cops," said Joe Backus, the manager of a musical instrument shop next to Café Racer. Police told employees and customers to stay inside while the search was going on, he said.
Nearby resident Evan Hill said he could hear the gunfire from his living room.
"I counted four or five shots and somebody shouting, and I ran out to my balcony and called 911," Hill told CNN affiliate KOMO.
Hill called the cafe a "very mellow" venue that hosts artwork and musical performances.
"It makes you kind of angry that it would happen in a place like that," he said.
Witnesses to the second shooting told police a woman and man were arguing in a parking lot when the man pulled out a pistol and shot the woman in the head. He took off in a black Mercedes sport-utility vehicle, which was found around noon in a neighborhood a few miles southwest of downtown with a pistol inside, Pugel said.
Seattle, a city of about 600,000, recorded 20 homicides in 2011, according to Police Department statistics. Wednesday's rampage brings 2012's year-to-date total to 19.
But Mayor Mike McGinn said there have been "multiple tragic episodes of gun violence" around the city in recent weeks. In an afternoon news conference with police, during which news of the suspect's shooting emerged, McGinn said ending that violence was "the highest priority."
"We will be working with our police to give them the tools they need to focus on violent offenders with access to guns," he said. "But it's also going to take a focus on the laws that make it too easy for people to acquire guns. And it's going to also take a full partnership with the community to end a culture of violence where young men believe it's OK to attempt to resolve disputes with violence, including guns."