"Isn't this a contradiction: God commands people to fear Him, yet I John 4:16, 18 says, God is love, and perfect love casts out fear?"
There are two kinds of fear, one of which is a necessary part of perfect love! Most people today are enslaved by harmful fears — chronic fears of danger and phobias of darkness, shadows, loneliness, blood, travel; fear of being unattractive to others; a morbid fear of death; etc.; ad infinitum. Such un-reasoned, chronic fears and worries rob people of contentment. The other kind of fear — the helpful kind — is fear of the bad result of wrong action. Proper fear stems from wisdom and knowledge. It warns of genuine dangers so we can take action to avoid them. The fear of God is in this category. Thus, "The fear of the Eternal tendeth to life; and he that hath it shall abide satisfied; he shall not be visited with evil" (Prov. 19:23). Proper fear takes two forms. One is the natural fear of physical danger — the warning we need to protect this temporal life. The other is spiritual fear for our eternal protection. Spiritual fear is called the fear of God. The fear of God warns us of those things which make life miserable and endanger our eternal life. It is a learned fear. We have to learn about the power and authority of God — that He gives life and also takes life. Spiritual, Godly fear is founded on living faith. Noah believed and feared God! This resulted in his being saved alive when the whole world perished (Heb. 11:7). Godly fear warns us that God will punish sin and wickedness (Prov. 16:6). It warns us to turn away from sin because it ends in death (Rom. 6:23). This kind of fear saves our lives! The fear of God is the instruction of wisdom (Prov. 15:33). God's Word tells us right from wrong — it warns of the consequences of sin and describes the blessings of righteousness (Ps. 1). Godly fear supplies motivation and furnishes impetus to obey His Word, to avoid pitfalls and mistakes that injure us. God is love (I John 4:8). He loves us (Rom. 5:8) and wants us to enjoy life forever in His Kingdom, His commandments are love (I John 5:3) — they point out the way of love and blessings. When we fear to disobey God, we are given the incentive to carefully weigh our thoughts and actions in the light of His Word and to avoid what is wrong. Thus, we are guided into the way of love that ends in every right result (Psalm 16:11). We become imbued with LOVE. The confidence and love which result, drive out and conquer the unreasoned, harmful, enslaving fears of man. This good kind of fear is like the healthy fear and reverence instilled in children by loving parents who teach their little children to fear to touch a hot stove Or run into the street. We are God's children, and He wants us to avoid the pitfalls of life. Thus, we fear and revere Him; and this fear to disobey teaches us perfect love. God's fear is good for us. It is really part of perfect love — the force that leads us to learn and live by the law of love. That is why a loving God tells us to fear Him!