President Martin Torrijos conceded defeat late on Sunday and promised to
respect the results.
Panamanians also elected a vice president, mayors and other local officials on Sunday.
More than 2.2 million people were eligible to vote.
Mertinelli's five-year term starts on July 1, when he is expected to implement a $5.25bn project seeking to increase the Panama Canal's capacity and allow it to accommodate larger ships.
Martinelli, who is pro-business and owns Super 99, Panama's largest supermarket chain, said he would work for a national unity government because "that is what the country is counting on".
"Tomorrow we will all be Panamanians and we will change this country so that it has a good health system, good education, good transportation and good security,'' Martinelli said.
"Martinelli has received strong support and I believe that he can achieve the change he's promised"
Voter Carlos Rodriguez
Herrera, 54, who served as housing minister under Martin Torrijos, the outgoing president, vowed to form "a responsible but very energetic opposition because we have stopped being a country of economic growth, with our house in order and a canal expansion plan in March".
Martinelli lost when he first ran for president in 2004 and returned for Sunday's election at the head of a four-party conservative coalition.
Many low-income voters voted for Martinelli whose government is struggling to rein in crime and high prices.
Panama, which uses the dollar as its currency, last year suffered its highest inflation levels since the early 1980s.
Inflation has since reduced as economic growth slows down but voters remain angry at higher prices.
Panama's economy has led Latin America with growth of around 10 per cent in recent years, fuelled by US-Asia trade through its transoceanic canal and robust banking activity.
But 2009 growth could slow to 3 percent or less as the global crisis hits credit and shipping.
Martinelli has promised "a massive public works programme "to return Panama to growth."
He wants to build ports, highways and a Panama City subway.
Thousands of Martinelli's supporters carrying the green flag of his party filled the streets of Panama City to celebrate.
"Martinelli has received strong support and I believe that he can achieve the change he's promised,'' said Carlos Rodriguez, a 46-year-old taxi driver.
"He has had great success as a businessman and now I hope he can to a good job in government."