Tolkien's cosmology works perfectly coherently within its own rules.
If you take a cyber analogy, you have an intelligent scientist who creates nano-bots one day. He creates them to have intelligence and choices, just like him. He decides how they are made and programmed but they are able to develop what he has given them - thus they are sentient nano-bots and have free-will. But remember the scientist was the one who chose what formulae are programmed in, he is omnipotent.
The nano-bots create a programme of an environment to live in, it even includes some glitches which one nano-bot has developed with the ability to alter the formulae it was given. The scientist creates the environment, despite the glitches (for reasons only known to him, but knowing techno-nerds, just for the sake of it being 'interesting'

) and also creates more nano-bots, v 2.0 and v 2.1. All the nano-bots go forth and multiply (so to speak

). They do all kinds of stuff, some of which the scientist might never have imagined, as he has given them the mathematical possibility of altering their programmes but at root, they were all programmed by him so he put the possibilities there and he retains the power to remove the batteries at any time.
Now the only way this would all fail is if one of the nano-bots did something that was mathematically impossible with what the scientist had programmed in. In that case we'd have to wonder if, on his tea break, the scientist's dad had sneaked in and tried to play the Sims on the PC and somehow messed up the programme...