The Jataka, Volume I, tr. by Robert Chalmers, , at sacred-texts.com
"Sense-lacking friends."--This story was told by the Master whilst on an alms-pilgrimage in Magadha, about some stupid villagers in a certain hamlet. Tradition says that, after travelling from Sāvatthi to the kingdom of Magadha, he was on his round in that kingdom when he arrived at a certain hamlet, which was thronged with fools. In this hamlet these fools met together one day, and debated together, saying, "Friends, when we are at work in the jungle, the mosquitos devour us; and that hinders our work. Let us, arming ourselves with bows and weapons, go to war with the mosquitos and shoot or hew them all to death." So off to the jungle they went, and shouting, "Shoot down the mosquitos," shot and struck one another, till they were in a sad state and returned only to sink on the ground in or within the village or at its entrance.
Surrounded by the Order of the Brethren, the Master came in quest of alms to that village. The sensible minority among the inhabitants no sooner saw the Blessed One, than they erected a pavilion at the entrance to their village and, after bestowing large alms on the  Brotherhood with the Buddha at its head, bowed to the Master and seated themselves. Observing wounded men lying around on this side and on that, the Master asked those lay-brothers, saying, "There are numbers of disabled men about; what has happened to them?" "Sir," was the reply, "they went forth to war with the mosquitos, but only shot one another and so disabled themselves." Said the Master, "This is not the first time that these foolish people have dealt out blows to themselves instead of to the mosquitos they meant to kill; in former times, also, there were those who, meaning to hit a mosquito, hit a fellow-creature instead." And so saying, at those villagers' request he told this story of the past.
Once on a time when Brahmadatta was reigning in Benares, the Bodhisatta gained his livelihood as a trader. In those days in a border-village in Kāsi there dwelt a number of carpenters. And it chanced that one of them, a bald grey-haired man, was planing away at some wood, with his head glistening like a copper bowl, when a mosquito settled on his scalp and stung him with its dart-like sting.
Said the carpenter to his sow, who was seated hard by,--"My boy, there's a mosquito stinging me on the head; do drive it away." "Hold still then, father," said the son; "one blow will settle it."
(At that very time the Bodhisatta had reached that village in the way of trade, and was sitting in the carpenter's shop.)
"Rid me of it," cried the father. "All right, father," answered the son, who was behind the old man's back, and, raising a sharp axe on high with intent to kill only the mosquito, he cleft--his father's head in twain. So the old man fell dead on the spot.
Thought the Bodhisatta, who had been an eye-witness of the whole scene,--"Better than such a friend is an enemy with sense, whom fear
of men's vengeance will deter from killing a man." And he recited these lines:--
So saying, the Bodhisatta rose up and departed, passing away in after days to fare according to his deserts. And as for the carpenter, his body was burned by his kinsfolk.
"Thus, lay brethren," said the Master, "in bygone times also there were those who, seeking to hit a mosquito, struck down a fellow-creature." This lesson ended, he shewed the connexion and identified the Birth by saying, "In those days I was myself the wise and good trader who departed after repeating the stanza."