Castle of Wizardry.
Other titles: The Belgariad, book 4.