fearing that the war against demons , sprites and fays was being lost , merlin brought the time of magic to an end , imprisoning both good and bad in a most enduring substance , to be withheld therein for over a thousand years .