Simply this.
God gave us free will. He allows us to follow or turn away from him. God knows what we will do. However, we have the power to control our responses. If God forced our hand, we would not have free will!
Some examples
God allowed Abraham to go up to the point of sacrificing his child, but not to actually do it. It was a test of Abraham's. And Abraham was better because of the test.
Did God know that Adam and Eve would fall? Yes, he knew but Adam and Even weren't perfect. God allowed them to suffer the consequences of their choices. If he prevented them from suffering for their choices, they would not have free will!
Summary
God allows us to either reap the benefits of following him or suffer the consequences of turning away form him. He knows beforehand what we will do, but we don't. So, he allows us to fail or succeed for our benefit.
An interesting (old) story about this:
St. Maximus ca. 580-662 a.d.
(The Life of Our Holy Monastic Father Maximus the Confessor and Martyr)
After quite some time, three men of high rank, Theodosius, Bishop of Caesarea in Bithynia, and the patricians Paul and Theodosius, were sent by Constans and Patriarch Peter to win over the saint. They were joined by the Bishop of Bizye, and alternately flattered and threatened Maximus, testing his faith and posing various questions. They began by introducing themselves, then requested Maximus to sit down. Bishop Theodosius asked, "How are you faring, my lord Abba Maximus?"
"Exactly as God knew I would before the ages," replied the saint. "He foreordained the circumstances of my life, which is guarded by providence."
"How can that be?" objected Theodosius. "Did God foreknow and actually foreordain our deeds from eternity?"
The saint said, "He foreknew our thoughts, words, and deeds, which nevertheless remain within our power to control; and He foreordained what befalls us. The latter is not subject to our control, but to the divine will."
"Explain more exactly what is in our power, and what is not," requested Bishop Theodosius.
"My lord, you know all this," answered Saint Maximus. "You only ask to try your servant."
The Bishop admitted, "Truly, I do not know. I wish to understand what we can control and what we cannot, and how God foresaw one and foreordained the other."
The venerable Maximus explained, "We do not directly control whether blessings will be showered upon us or chastisements will befall us, but our good and evil deeds most certainly depend on our will. It is not ours to choose whether we are in health or sickness, but we make determinations likely to lead to one or the other. Similarly, we cannot simply decide that we shall attain the kingdom of heaven or be plunged into the fire of Gehenna, but we can will to keep the commandments or transgress them."