This simple expression makes no sense whatsoever, since no one could rationally argue that all ends justify all means. Machiavelli's more nuanced statement that, in affairs of state, the results must be considered before judging the leader's decisions, is a more reasoned precept of realism.
But Machiavelli errs in several important ways in making this argument. First, he does not condition his advice by urging the "prince" to consider all moral alternatives before turning to the most expedient -- e.g., extinguishing the family line of political rivals. Second, he bases his advice on a very bleak assessment of human character, believing most people to be selfish, vile, fickle, ignorant, lazy, greedy, and prone to anger and vengeance. Third, he does not advise the "prince" to consider first the well-being of the people rather than his own power and control. And fourth, Machiavelli seems to ignore in The Prince the need to encourage the good in mankind, suggesting instead that it is better to rule by fear than by love.
Machiavelli avoided most of these errors in The Discourses, where he considered more deliberately the need for leaders to use good means as much as possible to achieve their goals, while also knowing how and being willing to use amoral means when society's survival was at stake.
In the world as it exists, where survival and transcendence occur as the yin and yang of evolutionary progress, it is vital that political leaders be very adept at weighing the pros and cons of alternative policies. The best tool for making this judgment is the higher mind, a capability all leaders of good will should strive to develop within themselves and encourage in others.