Abrim was the Grand Vizier of Creosote of Klatch. He got caught up in the events of Sourcery, took the Archchancellor's Hat from Rincewind and Conina and went mad as a result. Well, madder. He was already certifiably insane. It's in a Grand Vizier's job description, of course, along with being a manipulator and the true eminence grease behind the throne. He built a Tower of Magic in Klatch to fight those mages at Unseen University, was distracted by The Luggage and was killed by an attack from Marmaric Carding. Not for nothing is it said, "Never trust a Grand Vizier."
Abrim explains to Rincewind that he has magical potential and applied to the university but was considered too mentally unbalanced. This suprised Rincewind, as he was more than aware of the mental stability of most wizards could be described on a scale with the labels: 'Insane' and 'Insane beyond belief'.
Abrim wears the Archchancellor's Hat and becomes its vessel as he has enough magical power for the hat to use him. Abrim becomes possessed by the hat and becomes the paragon on wizardry, using sourcery as being wizardry itself he can use whatever magical power is already available. Abrim is killed in his battle with the wizards but one feels that he went as he wanted - foiled in a dastardly plan that can only have been executed by the Grand Vizier type.