The Warlock in Spite of Himself was the first book in the warlock of Gramrye series (excluding the prequel Escape Velocity) and was written by Christopher Stasheff in 1969.
The novel centers around Rod Gallowglass, a SCENT agent, who stumbles across the planet Gramarye. Immediately upon landing he is thrust into a world of medieval people, witches and warlocks, and all manor of mythical creatures. Rod is aided by his faithful companion Fess, an epileptic robot. While gathering intelligence, Rod discovers the planet is in political turmoil, due at fault to futurian influence on behalf of the PEST and VETO organizations who plan to corrupt the planet away from democracy, which Rod plans to bring to the planet, due to the planet's importance to the future of the DDT. The three main factions are the Monarchy led by Queen Cathrine, the beggars led by Tuan Loguire, and the Noble Lord eventually led Anselm Loguire.
Unfortunately for Rod when going to an inn for the night he is attacked by Big Tom. Rod defeats him, almost too easily, and Big Tom becomes a squire for Rod. Shortly thereafter the "wee people", who saw him land, declare him a warlock and put him to a test if he is good or evil by forcing him to fight a werewolf. Upon defeating it, with garlic sausage, he is returned to the inn he was staying at. The next day Rod and Tom head to Cathrine's castle to get themselves positions as soldiers. To do this however Rod is caught up in a fight with Brom O'Bernin, a dwarf who is advisor to the Queen. Though defeated Rod is permitted to join the Queen under the promise the solve the mystery of the Banshee which continuously is spotted upon the castle battlements, Rod discovers it to be a hologram machine set upon the castle roof, he quickly disables it and is sent out for his next mission.
Rod is then sent to gain intelligence on the Lords who have assembled at the fortress of Duke Loguire. On his way to the fortress Rod encounters a which of his own age named Gwendalyn. Gwen and Rod become in love but Big Tom tells Rod he should stay away from her. Passing themselves off as minstrels they gain entrance to the fortress and find the old Duke loosing his grasp on the other lords. Rod discovers each lord has a new advisor, who are PEST agents. Rod seeks more answers by exploring the haunted areas of the fortress but hence the name he encounters ghosts. Thanks to Fess the ghosts give up trying to stop Rod an allow him free access. Rod discovers a passageway behind the Duke's seat in the great hall, which he later uses to save the Duke when the lord's turn on him. However the ghosts discover that Gwen had followed Rod and return her to him. Upon saving the Duke, who is the replaced by his son Anselm., they make their escape into the forest and back to the Queen's castle. However, not having the full story, the Queen imprisons the old Duke Loguire for high treason and attempts to imprison Rod and Tom for aiding him until Brom comes to their aid and Cathrine lets them free.
Events soon take a turn for the worst when Rod finds himself betrayed by Big Tom, who is revealed to be a VETO agent from the future. Rod is imprisoned in a local inn VETO is headquartered at called the House of Clovis with some very unlikely cell mates. Tuan Loguire had been betrayed by the VETO leader in the House named the Mocker, and Big Tom, having had second thoughts about betraying Rod, was also thrown in Jail. While in jail the Mocker's plan is unveiled that he, with his lieutenants armed with futuristic guns, would throw the country into anarchy. In an escape plan Rod contacts fess for help who in turn calls for Gwen who had been hiding with Fess. Gwen calls he elves for help who in turn send the Prince of Elves to break Rod out. To Rod's surprise the Prince of Elves turns out to be Brom O'Bernin. Rod, Brom, Tuan, and Tom return to the castle to form a plan to overthrow the Mocker. Though at the castle tensions are high between Tuan and Cathrine.
Rod, Tom and Tuan return to the House of Clovis with their plan to kill the Mocker. They succeed and the beggars are united under Queen Cathrine. With their new forces assembled Cathrine's forces march out to confront the Lords. A great battle ensues but Rod notices the advisors, led by Durer (Anselm's advisor), are building a large weapon to quickly decimate the Royal army. However the advisors are wielding energy sword and Big Tom, in an attempt to kill Durer, is killed. Rod, having witnessed Tom's death, rides with haste wielding a blaster from Fess's saddle and kills Durer.
After the battle, with Rod's intervention, Tuan and Cathrine are married. Rod sent a message to SCENT stating that he was quitting to stay on Gramarye with Gwen, but quickly receives a message back requesting he stay on as the permanent SCENT agent of Gramarye. He immediately proposes the Gwen but she refuses to let him kiss her until he admits he is a warlock, and Rod then for the first time states that he IS a warlock.