In the novel Lord of the Flies, Golding shows many evil events happening on the island to boys who essentially have turned into savages. However, he does not allow evil to always triumph. If you look at the end of the novel when Ralph is almost cornered on the beach which will mean his death, a naval officer appears from an off-shore ship. This officer and the ship are a symbol of and mean a return to civilization where rules are followed, and people supposedly behave in civilized ways. The boys who are left will be returning to that world, leaving behind as best they can the savagery with which they lived on this island. Ralph can become a leader again in a society which will accept his qualities if he can forget what happened on the island. So, though Golding shows evil triumphing in many ways in the book, the ending reminds the reader that good can triumph also.
At the time he wrote the novel he admitted his view was exactly that one. Evil is part of humankind. In his lectures at University, some time after the publication of the novel, he said his opinion then changed but when he wrote "The Lord of the Flies" his opinion on humankind was absolutely pessimistic.
Just consider that during one of these lectures he explicitly said "...anyone who moved through those years (he refers to WW2 / concentration camps etc) without understanding that man produces evil as a bee produces honey (he means evil comes naturally to man), must have been blind or wrong in the head."
You can find this in his work "The hot gates"