A good Samaritan with a broken bottle and gaggle of bystanders stopped a man from escaping after stabbing another man on a crowded section of North Avenue Beach earlier this week, Cook County prosecutors said Thursday.

Pablo Sosa had snatched a bicycle and was about to ride off into the sunset after stabbing a 25-year-old man nine times at the beach around 6 p.m. on Tuesday, Assistant State’s Attorney Lorraine Scaduto said at Sosa’s bond hearing.

A police report said Sosa had attacked his victim with “a knife in each hand.”

But an unknown man socked Sosa in the head with a bottle as he tried to flee, and bystanders surrounded Sosa until police arrived, Scaduto said.

Sosa, who was hospitalized and did not appear in court Thursday, was ordered held in lieu of $750,000 bail on charges of attempted murder and aggravated battery with a deadly weapon.

Sosa suffered cuts and a torn tendon in his knee, Scaduto said.

His victim also remained hospitalized at Northwestern Memorial Hospital, having suffered a punctured lung, five stab wounds to his back, three wounds to his arm and one to his armpit, Scaduto said.

Sosa and his victim had encountered each other about an hour before the attack.

Police earlier had described the fight as a “domestic incident,” but Scaduto did not offer a motive for the attack.

The identity of the man who knocked Sosa off the bike is not known, the prosecutor said.