When Machiavelli lost his office, he desperately wanted to return to politics. He tried to gain the favor of the Medici by writing a book of what he thought were the Medici's goals and dedicating it to them. And so The Prince was written for that purpose. Unfortunately, the Medici didn't agree with what the book said, so he was out of a job. But when the public saw the book, they were outraged. The people wondered how cruel a man could be to think evil thoughts like the ones in The Prince, and this would come back to haunt him when he was alive and dead. However, if the people wanted to know what Machiavelli really stood for, they should have read his "Discourses on Livy", which explain his full political philosophy. But not enough people had and have, and so the legacy of The Prince continues to define Machiavelli to the general public.
;-)