In order to get what you wanted (the end), you had to use a certain "means" of doing something.
For example, in order to lose 50 lbs, I had to exercise every day, stop drinking soda, and go to bed early. But the end (losing 50 lbs), justified the means (forcing myself to exercise and giving up my favorite foods).