Patents create short term monopolies that can last up to 20 years. The idea is that the time is needed to provide the patent pioneers time to recoup the money it took to research and develop the product. When the patents expire patent holders in the pharmaceutical industry have generally employed a number of strategies to effectively extend the patients and ward off competition.
Strategy one: Marketing
Strategy two: Moving customers to drugs that are still protected by a patent
Strategy three: Paying potential competitors not to enter
See The Economist June 21, 2014 p. 74 for more discussion on the issue.