Interesting fact: In the story of David and Goliath, Goliath was thought to have had Gigantism, which caused a tumor to develop in his head, causing pressure in his brain behind his eyes. That gave him tunnel vision and meant he couldn't see David with the sling and it ruptured when he was hit in the head with a stone making him bleed out.

Saying that Goliath couldn't see David completely ignores the fact that Goliath was standing there taunting him. Also, saying he bled out because of a supposed tumor in his brain is irrelevant because David cut off Goliath's head with his own sword while he was lying there, which I would feel safe in assuring happened long before he bled out.

Going for full realism, a seasoned warrior would not take his eyes off of his enemy, even if he was a boy. Let alone allow him to load, spin and release a rock from a sling without either attacking first or blocking it with a shield. The tunnel vision meant he couldn't see the boy or dodge/block any incoming projectiles until it was too late.

Of course we'd never know exactly what happened because we only really have one source of reference and it's, shall we say, spotty at best. I'm just giving a scenario which could give it a basis in reality. As they say, all myths and legends have some grain of truth to start it.

Goliath was there with a spear, a javelin, a sword and his shield bearer. He was the champion of the entire Philistine army; and he had a whole other army too terrified to even come face him. So when a teenager strides up wearing no armour and only armed with a stick and a strap of leather, you can damn well better believe he's going to be rather cocky about it.
And since you pointed out that he wasn't taking his eyes off David, then his shield wouldn't be covering his head, where he was hit. And the Israeli slingshot was comparable to a bow, hurling 2" to 3" rocks at 200 feet per second, with an impact force of 5000 foot pounds.
I don't know the range, but the only things he had that could counter attack at the distance David would have been at to stop him firing would be his spear and javelin, both one shot weapons compared to David having a pouch full of stones. And knowing the result he obviously didn't get his shield up in time to block.
David was also a Benjaminite, a tribe so renowned for their skill with the slingshot they were said to be able to sling a stone at a hair and not miss.

Tl;dr Goliath was a cocky asshole, David was proficient in a weapon that could, and often did, penetrate armour and flesh. And then he cut off his head.

Without getting into an argument about whether the Bible is literal or not, the thing is we don't have an accurate account. People love to embellish stories of heroism and the underdog winning out. So we don't know exactly who Goliath or David was to their armies. They could both have been conscripted slaves, sent out to give the troops a performance before the battle, then they built up the story afterwards.

The basic facts we can draw from the story, if any of it is to be believed, is Goliath was a giant of a man, David was his opponent and Goliath died from a slung stone to the head. Those were the basis I used for my hypothesis.

The location it happened, the circumstances leading up to the battle and what happened afterwards could be distorted beyond any any true recognisable facts.

Although completely plausible, a slightly simpler explanation is that Goliath had gigantism, and David was able to kill him because he was skilled with a very deadly ranged weapon. Most people read the story and think "Oh, it has to be divine intervention because he killed a giant with a slingshot," but they overlook the lethality of the ancient sling. Greek and Roman military surgery manuals were incomplete with out suggestions on how to remove sling-shot from inside the human body, and in ancient times slingers were viewed as far more dangerous than archerers. So its is completely reasonable that a sling could put a rock through someones head.