The short answer
Machiavelli did not write this sentence. It does not appear in The Prince in that form, in Italian or in English. What The Prince contains is an argument — that a ruler will be judged by outcomes, and that conventional virtue may have to yield to the survival of the state — which readers have compressed, over centuries, into five words he never used.
Paraphrase promotion, again
This is the same mechanism that gave Gandhi his slogan and Voltaire his defence of free speech: an accurate-enough summary becomes catchier than the original, gets repeated, and eventually acquires quotation marks. The difference here is scale. What has been compressed is not a sentence but an entire book, and a great deal of Machiavelli's actual argument — its conditions, hesitations, and context — disappears in the compression.
An older source for the same idea
If you want a genuine classical line with this meaning, the Roman poet Ovid supplies one in the Heroides: exitus acta probat — the outcome justifies the deeds. It predates Machiavelli by roughly fifteen centuries and has the advantage of actually existing as a sentence.
Why the misquote flatters and distorts
Calling something Machiavellian is now shorthand for cynical ruthlessness, and the fake quotation is the main evidence people cite for it. But The Prince is a stranger, more circumstantial book than its reputation — closer to a manual about a specific political emergency than a philosophy of amoral striving. The five-word version is doing an enormous amount of work, and most of it is unfair.
What this means for your English
Watch how the eponym works: Machiavellian, Orwellian, Kafkaesque, Byzantine. English readily turns names into adjectives, and the adjective often drifts a long way from the person. Using these words accurately — knowing that Kafkaesque means bureaucratically absurd rather than merely strange — is a genuine mark of sophistication.