You actually have asked a very difficult question -- one that theologians have pondered for centuries, without ever solving completely.
Why is this? The reason is because the Bible assures us of two great truths that seem to our limited minds to contradict each other. On one hand, the Bible assures us that God is sovereign and all-powerful, and nothing happens that is outside of His control. No matter where we are or what we're doing, God's presence still surrounds us. The Psalmist declared, "If I go up to the heavens, you are there; if I make my bed in the depths, you are there" (Psalm 139:8).
But the Bible also tells us another important truth: Evil is real, and sometimes evil things happen that are not part of God's perfect will. Satan also is real, and although he is not all-powerful, he still wreaks havoc on our world. How is this possible, if God is in control? Only in heaven will we know the full answer.
But we do know this: God can be trusted, no matter what comes our way. We may not understand why He allows some things to happen -- but we can trust in God's love and mercy and goodness. We know this is true because Jesus Christ has demonstrated God's love and mercy to us. Is your faith and trust in Him? When it is, "You will not fear the terror of night, nor the arrow that flies by day" (Psalm 91:5).