When Il Principe (The Prince) was written by Italian historian and diplomat Niccolo Machiavelli the theme "usage of means which can be immoral can justify the aims of the rulers" spreaded to European Politics. Machiavelli mostly discussed the means of a ruler who aims to keep his state in power both internally and internationally. In addition, while realizing these aims the means need not to be ethical according to him. Means justify the end. He describes the abilities and virtues that a Pri,nce should have and means to achieve and sustain the power.
While conquiring a new state or territory, for instance, his recommendation to the ruler is to ruin them, installing a colony on that territory, and also installing a puppet regime to rule them. This puppet regime needs to be loyal to the ruler however it will make the people of that territory to feel like they are ruling themselves.
According to him, Princes or rulers who came to power and try to reform and change the old regime will come across with resistance of the people who are benefiting from the old regime. They will support reform if there is an opportunity for them to benefit from the new. According to him, in order to sustain the status quo and to secure his power the Prince can use immoral means to clear the protesters even execution of them and can also use force to his supporters in order to keep them loyal,
In military terms he recommends a self-sufficient army which does not include mercenaries or auxiliaries. Regarding the reputation of the Prince his recommendation is to keep the word only if it is suitable with his or state's interests.
In "The Prince" Machiavelli mostly mentioned realism instead of idealism. The immoral means mentioned in his book (executions, lies, brutal force...) according to him are necessary to keep a state in power in all terms.
Check the book The Prince here