The main advantage for these two nations was their geography.
Both countries, of course, are at or near the Straits of Gibraltar, where the Mediterranean meets the Atlantic. This is a very strategic place and was even more strategic back in these days. In the times just before overseas exploration, a great deal of trade with the Orient (the Middle East and beyond) came through the Mediterranean. Spain and Portugal could prevent any other nation's ships from passing through the Mediterranean if they wanted to.
Portugal, in particular, also benefited from having a tradition of seafaring because of its geographical location (Italy and Germany, for example, would not have had much reason to go out in the open ocean). It also benefited from having a more stable monarchy than some other countries that could have been competitors.
As Spain expanded into the Americas and Portugal moved into West Africa, Brazil and India, their military strength played an important role in their expansion. Military innovations such as firearms and well built and militarized ships gave these European countries an advantage over the indigenous people of their acquired colonies. Monetary strength from both financial endowments and trade kept the colonies financially strong. Both Spain and Portugal enslaved many of the original occupants of their conquests. Although slavery is considered immoral, at the time it helped secure these counties hold on their expansions by increasing the labor force. Spain especially benefited from the use of slaves to mine silver which greatly supported their economy in the 16th century. And finally, Spain and Portugal were successful in their expansions because they really didn’t have any additional European competition. Political weakness plagued Italy, England wasn’t interested in the Southern Hemisphere, and France was preoccupied with other matters.