HP's announcement on Thursday came as a surprise, since the company had reportedly been focusing lately on internal candidates. Apotheker's name had not been raised by industry pundits as a likely successor.
It also means that HP overlooked two internal candidates for the position -- Ann Livermore, the head of HP's enterprise business, and Todd Bradley, who runs its giant PC division.
The HP board also appointed Ray Lane, a former Oracle president, to be its non-executive chairman. Like Livermore and Bradley, Lane had been seen as a possible contender for the top job.
Both appointments are effective Nov. 1, HP said.
Apotheker will likely be seen as a controversial choice. He spent more than 20 years at SAP, becoming joint CEO in April 2008 and then its sole CEO in May 2009. His tenure as sole CEO lasted less than a year, however, and Apotheker resigned unexpectedly in February after SAP's supervisory board opted not to renew his contract.
HP praised Apotheker's long career and said he was "a driving force in making [SAP] the largest business software applications company in the world."
"Leo is a strategic thinker with a passion for technology, wide-reaching global experience and proven operational discipline -- exactly what we were looking for in a CEO," HP said in a statement.
His experience in the software industry may also have been a factor. HP's future lies to some extent in expanding its software portfolio to better compete with IBM and Oracle, said Ray Wang, a partner with technology consulting company Altimeter Group.
"HP needed a tech leader, someone who has run a billion-dollar business, someone who has a global perspective and a software perspective to help the company get more into the software business, and there aren't too many people like that walking the street," Wang said.
HP will likely be on the lookout to partner with and acquire software businesses, he said. Indeed, speculation about a possible acquisition of SAP may intensify in the wake of HP's announcement, but the company is more likely to buy a company with more of a "cloud orientation," Wang said.
"There's always been rumors about SAP being acquired, but a SaaS-oriented company like Salesforce.com would likely make more sense," he said.
HP had been without a full-time CEO since the first week of August, when Hurd abruptly resigned following claims of sexual harassment from the actress Jodie Fisher, who had worked for HP as a marketing contractor.
HP decided Hurd had not violated its sexual harassment policy, but it faulted him for failing to disclose a personal relationship with Fisher, and for filing inaccurate expense reports intended to conceal the relationship.
HP's chief financial officer, Cathie Lesjak, was named interim CEO while HP looked for a new leader.
Other names mentioned as possible replacements for Hurd included Michael Capellas, the former CEO of Compaq.
HP's shares dipped in after-hours trading following the announcement Thursday. Its shares were selling for US$40.75 at the time of this report, down 3 percent from the close of market.
HP has looked outside the company for its two previous CEOs -- both of whom were ultimately edged out by the board. Carly Fiorina was hired in 1999 and forced out six years later after HP's controversial acquisition of Compaq. Hurd became CEO that year, in 2005, and also left at the board's urging.
The bizarre tale of Hurd's departure captivated the tech industry for a while, with some speculating that there were other motives for his departure. Oracle CEO Larry Ellison jumped to Hurd's side, calling HP's board "cowardly" for letting him go.
A few weeks later, Oracle hired Hurd as a co-president to run its systems business, formed through the acquisition of Sun Microsystems earlier this year.
HP subsequently sued Hurd, saying that he would not be able to perform the new job without violating a confidentiality agreement tied to his severance package. The companies quickly settled the suit without disclosing the terms. HP said Hurd would adhere to his obligations to protect HP's confidential information.
Hurd made his first appearance as an Oracle executive at the OpenWorld conference last week.
His departure didn't stop HP moving forward with deals. Earlier this month it prevailed in a lengthy bidding war against Dell to acquire storage vendor 3Par for $2.35 billion. Two weeks later it acquired security vendor ArcSight for $1.5 billion.
There's a certain symmetry in the recent career paths of Apotheker and Hurd. Both left their CEO jobs abruptly, only to resurface soon after with top jobs at other companies.
At Oracle, Hurd now competes with his former employer, HP. And HP has hired a CEO with plenty of experience competing against Oracle.
Apotheker's departure from SAP followed a difficult time for the company. Its revenue had been declining in the poor economy, and SAP was struggling to keep up with industry trends like cloud computing. In addition, an increase in its maintenance fees in 2008 caused deep resentment among some customers.
Apotheker addressed some of those factors in a memo to staff upon his departure.
"Confronted with the worst and most brutal economic crisis since the Great Depression, and faced with the consequences of decisions and actions made in the past, the Executive Board under my leadership had to take some very difficult decisions to steer SAP through the worst storm in its history," he wrote. "Yet we didn't simply try to maneuver SAP thru the economic crisis. Indeed, we simultaneously started to build the foundation for a brighter future."
HP has scheduled a webcast Friday morning to discuss the appointments with analysts and shareholders.