The Israelites were at war with the Philistines in the Jezreel Valley, and the Philistines attacked on the slopes of Mount Gilboa. They killed three of Saul’s sons - including Jonathan. A Philistine archer severely wounded Saul. Seeing that he would be captured, Saul killed himself by falling on his sword. This ceremonial suicide was an ancient way to preserve honor in defeat.
By the way, since he was on the outs with Saul at this time, David was not involved in this battle. (See 1 Samuel 31.)
Also, cool ... check out this fascinating painting of this scene by Pieter Bruegel the Elder