It all happened within the space of two years.

First, IBM unveiled its line of powerful Personal System-2 computers intended to leave the ubiquitous PC clones in the dust. Next, the company decentralized and shook up its top management. Finally, IBM introduced its mid-range AS-400, a machine that independent consultant Michael Killen calls "the greatest computer ever produced."Two short years after major business publications proclaimed that "Big Blue has the big blues," IBM - paced by an almost totally revamped product line and a scrappy new attitude - is bouncing back. The turnaround comes despite some apparent missteps in the key personal computer arena.

"IBM has spent the better part of the last three years performing major surgery," pruning over 16,000 jobs, reassigning over 20,000 employees and redesigning major products, says John B. Jones Jr., an analyst at Montgomery Securities in San Francisco. "Now, aided by the new product cycle and with costs under control, IBM is beginning to reap the benefits."

Mainframe computers were sold out for the month of September, according to a Montgomery Securities survey of 4,500 IBM customers, while mid-range systems were enjoying a "dramatic pickup" after years of pounding by Digital Equipment Corp. Growth in revenue will exceed cost growth for the first time in four years years, Jones says, forecasting 1988 revenue of $58 billion, up 7 percent from last year, and essentially flat costs.

For the first half of the year, IBM posted net income of $2.21 billion, up from $1.96 billion a year earlier.

"The pieces are in place for some major league growth in 1989," adds Steve Cohen, an analyst for Gartner Group.

The optimistic forecasts could be derailed if the economy were to slip into recession next year. A shock like last October's stock market crash could also lead to a drop-off in orders, as happened a year ago. Still, analysts say that IBM is in better condition than it has been in a long time.

The good reviews come despite some well-publicized stumbles in personal computers, where IBM's growth rate of around 20 percent pales in comparison to the 30 percent to 50 percent gains being posted by such rivals as Compaq, AST, Tandy and Apple.

Another red flag was raised last month. In the first major challenge to IBM's role as the setter of standards in the PC business, Compaq emerged as the leader of the "Gang of Nine" makers of IBM-style PCs that will contest IBM's new personal computer design.

The PS-2 models, besides their intended role of clone killer, have been billed as products that will allow businesses to easily connect personal computers into networks that include bigger mid-range systems and mainframes. Promised - but as yet undelivered - "Presentation Manager" software will provide greater ease of use, and a new operating system called OS-2 will allow most models to perform several tasks simultaneously.

But the Gang of Nine computer makers have rejected the idea of paying the fat royalties demanded by IBM for emulating the internal design of the higher-end PS-2 models. The nine companies - whose PCs, taken together, outsell IBM's by about 50 percent - said they would develop their own data pathway, the Extended Industry Standard Architecture.

IBM derides the challengers, but industry observers say their design offers buyers several pluses, including the ability to use expansion cards and other accessories from their first-generation PCs. With the PS-2, users must buy entirely new expansion cards and accessories.

The audacious challenge lends weight to arguments that IBM's April 1987 decision to discontinue production of its previous PCs in favor of machines incorporating the so-called Micro Channel data conduit was, at best, premature. The Micro Channel's benefits have proven ephemeral in the absence of new, more powerful software to take advantage of the technology.

"There is no doubt that IBM abandoned the AT-bus too soon," says analyst William Easterbrook of Kidder, Peabody & Co. in San Francisco, referring to the old data pathway. "IBM, quite literally, left hundreds of millions of dollars on the table for other firms to take - and they took it," Easterbrook adds.

Last month IBM adjusted its PS-2 strategy by unveiling a non-Micro Channel model. But the company still insists the PS-2 line is a success, with 3 million units expected to have been shipped by the end of this year. And IBM defenders say its line will pick up more customers - including the top corporate buyers - as benefits of the PS-2's ability to communicate with mid-range and mainframe computers become clearer next year.

Despite the criticism, IBM's board demonstrated its confidence in the future Tuesday when it authorized the expenditure of $2 billion to buy back IBM stock. The expenditure, which would retire about 3 percent of the company's shares outstanding at current prices, is by far the largest in a series of buybacks that IBM kicked off in May 1986.

Customers and other constituents of IBM say they are seeing a less complacent - yet humbler - company than the IBM whose growth stumbled in the mid-1980s. For example, after resisting for years, IBM has finally embraced the concept of "open networks" that can connect gear made by different manufacturers. It is providing standards and specifications to other manufacturers so that their machines and common software will work with IBM's.

"The primary reason we've done that is to remove inhibitors to growth in the industry," said James Vanderslice, an IBM executive with responsibility for telecommunications, in a recent speech, acknowledging that IBM's go-it-alone mentality won't cut it anymore.

In May, IBM took another big step toward working with some of its competitors when it joined with rival Digital Equipment and five other computer makers to develop a version of the Unix operating system that will rival American Telephone & Telegraph and Sun Microsystem's version.

The name for the new venture, Open Software Foundation, underscored the departure from IBM's practice of offering proprietary operating systems, which control a computer's basic functions. Unix allows machines to work smoothly with one another.

IBM is also wooing dealers and investors. "IBM had gotten a black eye in the investment community in recent years for being less than totally cooperative," says Jones of Montgomery Securities. This year, the firm dispatched its head of investor relations to Montgomery Securities' annual investors conference to meet individually and in groups with investors and potential investors.