Ale’s well that ends well.

A man confronted by a gang of teens — one of them with a knife — told the cops he frightened off the would-be robbers by swinging a bag of beer menacingly.

The man said he said he was walking home on Washington Street in Dorchester with three beers in a plastic bag shortly before 10:30 Friday night when more than a half-dozen boys and girls approached him in front of a fried chicken franchise and demanded he turn over his cell phone and wallet. One youth threatened him with a knife, the man told police.

Cops said the man told them “he had to swing a plastic bag which contained three cans of beer at the group” in order to fend them off.

Officers responding to the attempted armed robbery chased down and nabbed the kids, two of whom were arrested based in part on witness accounts: a 17-year-old male from Dorchester and a 15-year-old male from Randolph. Both were charged with armed robbery and delinquency.

The 15-year-old was also charged with resisting arrest and assault and battery on a police officer.

Police said the seized a black pocket knife as evidence.