BOSTON - In a startling turn, Boston Marathon bomber Dzhokhar Tsarnaev apologized for the lethal attack for the first time Wednesday just before a judge formally sentenced him to death.

"I am sorry for the lives that I've taken, for the suffering that I've caused you, for the damage that I've done -- irreparable damage," the 21-year-old college student said, breaking more than two years of public silence.

To the victims, he said: "I pray for your relief, for your healing."

After Tsarnaev said his piece, U.S. District Judge George O'Toole Jr. quoted Shakespeare's line about "The evil that men do lives after them" and told Tsarnaev that no one will remember that his teachers were fond of him, that his friends found him fun to be with or that he showed compassion to disabled people.

"What will be remembered is that you murdered and maimed innocent people, and that you did it willfully and intentionally. You did it on purpose," O'Toole said.

"I sentence you to the penalty of death by execution," he said.

Tsarnaev looked down and rubbed his hands together as the judge pronounced his fate.

The apology came after Tsarnaev listened impassively for about three hours as a procession of victims and their loved ones lashed out at him for his "cowardly" and "disgusting" acts.

"He can't possibly have had a soul to do such a horrible thing," said Karen Rand McWatters, who lost a leg in the attack and whose best friend, 29-year-old Krystle Campbell, was killed.

The outcome of the proceedings was a foregone conclusion: The judge was required under law to impose the jury's death sentence for the April 15, 2013, attack that killed three people and wounded more than 260.

The only real suspense was whether Tsarnaev would say anything when given a chance to speak near the end of the proceedings.

Until Wednesday, he had said almost nothing publicly since his arrest more than two years ago, offering neither remorse nor explanation.

His apology was a five-minute address peppered with religious references and praise of Allah. Speaking in the accent of his native Russia, he paused several times, looking as if he was trying to maintain his composure.

He stood and faced the judge while speaking, but spoke of the victims.

Twenty-four people in all gave so-called victim impact statements at the sentencing in federal court, some of the urging him to explain himself and utter the words of remorse they longed to hear.

Tsarnaev made it clear he was listening.

"All those who got up on that witness stand and that podium relayed to us, to me -- I was listening -- the suffering that was and the hardship that still is, with strength, with patience, with dignity," he said.