I drove onto the water
You use 'the' here as it refers to something you did (specifically, not generally- where did you drive onto the water?) If the sentence was general it would read 'I drove onto water'
I saw the milk spill
This sentence is not referring to milk in general, but rather specifically THE milk you saw spill (the milk in your kitchen, on the table, etc...)
I used to gaze at the moon as if in a prayer.
This is correct, you are gazing at the moon, as if you are saying a prayer (one of many prayers that you know)
I used to gaze at the moon as if in prayer.
The word prayer here is not referring to a prayer, but rather emphasises the action of praying.
He has a full knowledge of the ancient sciences.
Is the use of the correct here, as we are specifying these kind of sciences? This depends on whether you're speaking about a branch of ancient sciences (the ancient sciences; for example metaphysics) or ancient sciences as a whole (ancient sciences in general).
I hope this helps