WATERTOWN — Four days after two deadly explosions turned the finish line of the Boston Marathon into a scene of bloody chaos, the 19-year-old college student believed to be responsible for placing the bombs was taken into custody tonight, bringing a sense of relief and justice to a shaken region.

Dzhokhar A. Tsarnaev of Cambridge was pulled from his hiding place in a boat parked behind a house on Franklin Street shortly before 8:45 p.m. in this community just outside Boston.

“We are eternally grateful for the outcome here tonight. We have a suspect in custody,” said Colonel Timothy Alben, commander of the State Police. “We’re so grateful to bring justice and closure to this case.”

“It’s a night where I think we’re all going to rest easy,” Governor Deval Patrick said at a news conference in Watertown.

With the second suspect in the case, Tsarnaev’s brother, Tamerlan Tsarnaev, 26, fatally shot in a gun battle with police early this morning, Boston Police Commissioner Edward F. Davis said, citizens “can be confident that the threat has been removed.”

President Obama, speaking at the White House tonight, said, “We’ve closed an important chapter in this tragedy.” But he also said there were “still many unanswered questions” and said the FBI would thoroughly investigate.

Dzohkhar Tsarnaev, who exchanged gunfire with police from the boat, was rushed to a local hospital, where he was in serious condition, Davis said.

Police had approached him cautiously, worried that he might be wearing a suicide bomb vest.

The apprehension of Tsarnaev was the latest stunning development in a day of mayhem that had shocked the city, even as it was still reeling from Monday’s Marathon attacks. An MIT police officer was killed, “assassinated,” Thursday night in Cambridge. Then a carjacking was reported. Officers pursued the car, which turned out to contain the two Tsarnaevs, who threw explosives at them.

The elder brother was shot by police early Friday in a gun battle in Watertown, in which fficials said they wielded improvised explosive devices and homemade grenades. Dzhokhan Tsarnaev was so desperate to escape he ran over his brother as he lay wounded. He later abandoned the car in Watertown and fled on foot, disappearing from sight.

Law enforcement mobilized, sending legions of heavily-armed police officers to search a 20-block area of the community. At the same time, Governor Deval Patrick took an unprecedented security step, asking people in Boston, Watertown, and several other nearby communities — totaling a million people — to “shelter in place” — stay at home behind locked doors and open up only to police officers with proper identification.

Government and business offices closed as police cars zoomed on mysterious errands on deserted streets. The Red Sox and Bruins games were canceled, as well as the Big Apple Circus. Amtrak was shut down from Boston to Providence, as well as the MBTA, the Boston area’s public transit system. The region came to a standstill.

Then, at 6 p.m., officials held another news conference to say that despite the massive manhunt, they had come up empty. The suspect had slipped outside their perimeter. Officials said they remained determined to find him, however, and that they believed he was somewhere still in Massachusetts. Patrick dropped his request for people to shelter in place and ordered the MBTA to resume service.

The dramatic finale came less than an hour after the news conference was over. A resident of Watertown came out of his house and noticed blood on his boat and that the tarp covering it was ripped. He lifted the tarp and saw a bloody form. He called police, who raced to the scene and exchanged gunfire with Tsarnaev, said Davis, the Boston commissioner

Police surrounded the boat and there was a standoff for about an hour and a half. A State Police helicopter peeked at him from above, using a special infrared camera. Police deployed “flash bang” grenades to stun and distract him, Davis said. Police were cautious in their approach, concerned that Tsarnaev could be wearing a suicide bomb vest.

A Globe photographer at the scene could hear police calling, “We know you’re in there. Come out on your own terms. Come out with your hands up.”

An FBI hostage rescue team was eventually able to pull him out.

In yet another twist in the story, New Bedford police said this evening that three people had been taken into custody in their city as part of the bombing investigation.

New Bedford Police Lieutenant Robert Richard said his department assisted federal investigators in executing a search warrant at a home on Carriage Drive, about 10 minutes from the University of Massachusetts at Dartmouth, where Tsarnaev was a student.

MIT Police Officer Sean Collier, 26, of Somerville, who was fatally shot while sitting in his cruiser near Main and Vassar streets in Cambridge, in what Davis called an “assassination,” was remembered as a brave and devoted officer.

MBTA Transit Police Officer Richard H. Donahue Jr., 33, who was shot as officers pursued the Tsarnaevs into Watertown, was in critical but stable condition at Mt. Auburn Hospital.