According to Heritage History, Napoleon attacked Portugal due to the country's refusal to join his Continental System. In 1806, he attempted to wage economic war by forcing France, its captured territories and the country's allies to refuse to do business with England in an attempt to weaken the island nation. Portugal refused to play along and signed a treaty with England, and in response, Napoleon invaded Portugal in 1807.
At the dawn of the 19th century, France could not match the naval power of its rival England, so Napoleon attempted to wage war economically on his enemies. Portugal's refusal to join in this attack served as an easy justification for his invasion, but in addition, he clearly wanted access to Portugal's navy to bolster his own forces. Portuguese ships were considered almost the equal of British ones, and even a few more vessels could prove valuable. The British quickly came to Portugal's aid, and coupled with insurrections inside Spain, this military maneuver stymied the French and prevented an easy takeover. Ultimately, the political situation on the Iberian peninsula required far too much of the empire's resources to control, and Austria's eventual entry into the war redirected Napoleon's attention to more pressing matters than the nation of Portugal.