If you accept Scripture there are three certainties related to your question.
1. Yes, God knows all things. He is omniscient.
2. And, yes, we are responsible for our actions. Free will is very much misunderstood. None of us is free to do what is inconsistent with our nature. We can't flap our arms and fly. However we have a significant choice before God. We are not robots. We are responsible for our actions and their consequences.
3. Third certainty - It's a mystery. That's not a copout. It's only reasonable that if God is infinite we finite creatures would be unable to comprehend Him fully. Humbly walking with God calls us to accept the mystery and not use it as an excuse for ignoring what is clear and right before our faces.