The appointment, announced on Thursday, came as a surprise, since HP 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.
Also on Thursday, the HP board appointed Ray Lane, a former Oracle president, to be non-executive chairman of the HP board. Like Livermore and Bradley, Lane had been seen as a possible contender for the top job.
Both appointments are effective from November 1, HP said.
Apotheker will likely be seen as controversial choice by the HP board. He spent more than 20 years at SAP, becoming joint CEO in April 2008, and taking over as 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.
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 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 in late September.
HP appears to have moved on. 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.