"No harm befalls the righteous, but the wicked are filled with trouble"
This is a statement of Solomon’s observation. It sounds wrong, but you have to look beneath the surface to see what Solomon is saying. The word harm is the Hebrew word aven, which means vanity, unrighteousness, mischief, sorrow. The word befalls is the Hebrew word anah, which means happen upon, meeting, approach. The key idea in this proverb is that God protects the righteous from chance evil and harmful difficulties. The wicked, on the other hand, are always around that which is harmful and are constantly bumping into and having chance occurrences with problems, difficulties, and the like.
It is not that the righteous don’t have bad things happen to them, but they do not have chance or random evil happen to them. God protects them from those things. The things that God lets into the righteous person's life are there for a reason. The life of the wicked has lots of chance destruction that pour into their lives.
Solomon is saying that if you live the righteous life (stay within the Ten Commandments), you will not have all these bad things just happen to you. He is saying that he has watched people live both ways and what he has noted is that the wicked have one tragedy after another slam into their lives unannounced and unwanted. But the righteous are protected from so much. On one hand, it is because they do not constantly live around evil and selfish pursuits. And on the other hand, God keeps the righteous from being impacted by them.
I have heard some people say that they think that they are cursed because all kinds of bad things keep happening to them. Solomon is saying that you are not cursed, you are wicked. There is a level of selfishness in how you are living that has moved you outside of God’s moral boundary structure and, therefore, random evil and chance destruction slams into you. Get out of there – repent of your selfishness and run to Jesus for forgiveness and a new start.