The short answer
Not quite. He said it would be best to be both, that it is hard to be both at once, and that when you have to choose, being feared is safer. Then he set a limit that almost never gets quoted.
What chapter 17 says
It would be desirable to be both loved and feared, he writes, but it is difficult to be both at once, so it is much more safe to be feared than to be loved, when you have to choose between the two.
Both, if you can. Safer, not better. And only when you have to choose.
The limit
A paragraph later: be feared in such a way that if you are not loved, you are at least not hated. And the way to avoid hatred is plain: leave people their property and their women.
How it became a tyrant's rule
In 1576 the Huguenot lawyer Innocent Gentillet reduced Machiavelli to fifty maxims, each stated in a sentence and refuted. In Gentillet this one is a rule: a prince should be feared rather than loved. Keep the conclusion, drop the condition, cut the limit, and a working politician's trade-off has become a tyrant's rule. That version travelled further than the book.