Lord of the Flies, by William Golding, is an allegorical novel, as mentioned in the answer above. What happens with these boys on this island is a microcosm (a small picture) of what is happening in the rest of the world, and the ending reminds us of that.
The boys on this island have no adult supervision and no laws or restrictions to keep them in line; their only governance is their own self-control, something they demonstrate almost from the beginning that they have very little of. Jack and his hunters transform into savages, and by the last chapter of the novel every boy on the island--except for Ralph--is either dead or part of Jack's tribe. Golding rarely uses any names besides Jack or Ralph in this chapter, referring to all the other boys simply as savages.
Jack has mandated that Ralph must be killed, and his savages try to obey their chief. Soon a fire is lit which parallels the fire they lit at the beginning of the novel; soon it is out of control and threatens to consume the entire island. Ironically, the fire which was set to kill Ralph is also the fire which signals a passing military vessel and ultimately saves them.
The final images of the novel, when the crisply uniformed naval commander arrives, are powerful primarily because readers are reminded of several realities. First. we see these boys as they are through the eyes of the naval officer. While we see them as howling savages bent on murder, he sees them as a "semicircle of little boys, their bodies streaked with colored clay, sharp sticks in their hands, ...standing on the beach making no noise at all." We know that Ralph is running for his life from a group of savages. but to the officer he is "the little scarecrow in front of him. The kid needed a bath, a haircut, a nose-wipe and a good deal of ointment." Jack is determined to kill Ralph, but to the adult he is a "little boy who wore the remains of an extraordinary black cap on his red hair and who carried the remains of a pair of spectacles at his waist." This contrast is a clear reminder that these are mere boys, a horrible reminder of what even children are capable of without the restraints of civilization.
The naval officer jokingly asks if they have been playing war; he has no idea (until Ralph tells him) that the boys are involved in a true war. Seeing this man and his ship is a reminder to us that what has been happening on the island is the same kind of thing which has been happening in the "real" world of adults (World War II).
The impact of this intruder from the outside world adds emphasis to the events of the story and reminds us that we are not immune from such things.