LOS ANGELES — Hewlett-Packard Co., battered by declining profits and tech rivals with flashier hand-held devices, is slashing 27,000 jobs, or 8 percent of its workforce.

LOS ANGELES — Hewlett-Packard Co., battered by declining profits and tech rivals with flashier hand-held devices, is slashing 27,000 jobs, or 8 percent of its workforce.

The Silicon Valley tech firm, one of the world's largest computer makers with nearly 325,000 employees, said the job reductions — through layoffs and a voluntary early retirement program — would occur by the end of fiscal 2014. The cuts are expected to save the company $3 billion to $3.5 billion annually. "Workforce reductions are never easy," Chief Executive Meg Whitman said in a call with analysts. "They adversely affect people's lives, but in this case they're absolutely critical for the long-term health of the company."

The move was widely expected, as HP has struggled for months to turn its business around.

The company has seen customer demand for its PCs plummet in favor of tablets and smartphones made by Apple Inc. and other competitors. Analysts have criticized the company for its lack of direction and for developing products too late. Profits and employee morale have eroded, and instability at the top has added to HP's woes; last fall Whitman became the firm's fourth CEO in little more than a year.

HP said the majority of the savings from the job cuts would be reinvested back into the company, specifically to boost investment in cloud computing, data analytics and information technology security. It didn't specify which business units or countries would be targeted, but a company spokesman said the cuts would impact "nearly every business and region."

After the "chaos that engulfed the company last year," Wednesday's move was much needed, said Michael Holt, senior equity analyst with Morningstar Inc. HP should "invest in technology that will shape the next decade rather than today's portfolio, which is a little outdated," he said.

The Palo Alto, Calif., company announced the job eliminations the same day that it reported second-quarter earnings that beat analysts' expectations. For the three months that ended April 30, HP reported profit of $1.59 billion, or 80 cents a share. That was down 31 percent from $2.3 billion, or $1.05, in the same quarter a year earlier.