The Amulet of Samarkand by Jonathan Stroud

Nathaniel is an ambitious young magician who summoned a 5000 years old Djinni for some petty revenge. Little did he know, he would end up tangled in some dangerous political plot against his will.