TOKYO -- Its electronics are profitable again. Its bottom line, once deep in the red, is in the black. Its engineers are flexing their product development muscle.

Sony is back. And its goal of booking a 500 billion yen ($4.95 billion) operating profit for the first time in two decades suddenly seems within the realm of possibility.

But before investors and consumers fully buy into the turnaround, the company will have to do what it once did so well: wow the world. Sony hopes to do just that with a combination of robotics, artificial intelligence and everyday gadgetry.

For decades, Sony looked invincible. The company behind the Walkman and PlayStation had such a powerful brand that its products practically sold themselves.

Then, in the span of a few years, a name that had symbolized innovation and success began to carry connotations of predictability and decay. From fiscal 2008 to 2014, Sony accumulated over 1 trillion yen ($9.91 billion) in losses. A retired company executive summed up the malaise this way: "Sony has become a bureaucratic organization that is unable to take risks."

The responsibility for reversing the earnings erosion and cultural deterioration -- if they could be reversed -- fell to President and CEO Kazuo Hirai, who took office just after the company logged a record 456 billion yen net loss for the year ended March 2012. Some wondered whether Sony had what it took to compete in an era where software, not hardware, was king.

Yet, here we are in 2016, and Sony has just posted its first consolidated net profit in three years -- 147 billion yen. It is the first time in seven years that the company has managed to turn a profit excluding one-offs, such as proceeds from property sales.

More crucially, perhaps, electronic hardware turned profitable for the first time in five years. That excludes game consoles, which were already money-makers.

After a series of bold restructuring measures, Hirai and a team of innovators are determined to ensure the turnaround is no fluke.

"SONY 2.0" One key player is Hiroaki Kitano, president and CEO of Sony Computer Science Laboratories. Kitano developed the Aibo robotic dog -- a product that attracted a devoted following but was cut as Sony's earnings worsened back in 2006. He is still regarded as a guru in the field of robotics and artificial intelligence.

This past February, Kitano stopped by Hirai's office on the 20th floor of Sony headquarters in Tokyo's Shinagawa district. On the table, he unfurled a 1-meter by 2-meter chart, titled "Sony 2.0," that plotted a course toward new products and business domains.

Sony CSL is a research arm separate from the main corporate machine. From his perch there, Kitano had been watching the company almost as an outside observer. Hirai was so impressed with Kitano's pitch that he decided they should meet regularly.

Recent personnel moves reflect Hirai's desire to make better use of the company's engineers and scientists, with an eye toward finding commercial uses for AI and robotics. Faced with workforce cuts and casualties like the Aibo project, Sony insiders fought to maintain the company's development capabilities. Now Hirai is giving them a chance to unleash those capabilities anew.

Last autumn, Hirai decided to establish a department devoted to mid- and long-term business development. He appointed Toshimoto Mitomo, an executive well-versed in technology management, to lead it. Mitomo immediately asked Kitano to get involved, along with Masahiro Fujita, a leading AI engineer who worked with Kitano on the Aibo and a humanoid robot called Qrio.

The new department was officially launched in April, with Fujita serving as chief technology engineer.

Sony's board of directors has added impetus for Hirai's plan to focus on AI and robotics. Last December, the board gathered in the Izu resort area, southwest of Tokyo. Outside directors Joichi Ito, head of the Media Lab at the Massachusetts Institute of Technology, and John Roos, a former U.S. ambassador to Japan and Silicon Valley lawyer, stressed that Sony should put its chips on AI.

Mitomo, Kitano and Fujita continue to brainstorm with AI and robotics experts from across the Sony group, including people from Sony CSL's Tokyo head office and its lab in Paris. And they are doing more than just talking among themselves: In May, Mitomo and Kitano negotiated a deal to invest in U.S. AI startup Cogitai.

Seeking still more AI and robotics insights, Sony in June set up a panel of experts from around the globe. The participants hail from companies in which Sony holds stakes as well as outside entities.

The manufacturer's approach to recruitment is shifting to match its new technology strategy. "We would like to hire young people who are eager to succeed, rather than well-known veterans, from around the world," Kitano said.

In July, Sony sponsored the International Joint Conference on Artificial Intelligence in New York for the first time, hoping to find some fresh talent. The company put up a web page to recruit conference participants, stating: "Now, Sony is taking on a new challenge in the world of robotics and AI. We are seeking unique and talented individuals who have passion for 'moving' people through our wide variety of products, content and services."

Sony is "actively recruiting AI and robotics personnel" in Japan as well, said an executive at a staffing company.

At a corporate strategy presentation held for investors, analysts and the media on June 29, Hirai spoke of Sony's desire to create a robot that "connects" with people and conjures up feelings of "affection." The presentation, personnel appointments and investments leave no doubt that Sony management is fully committed to robots and AI.

But after bleeding so much red ink, how exactly did Sony regain the strength to make such a commitment?

LOST IN A DIGITAL WORLD Founded in 1946, amid the ashes of World War II, Sony developed one of the world's first transistor radios for consumers, followed by several other iconic products. The early 21st century, however, was not kind to the company. In April 2003, it revealed disappointing results for the just-ended fiscal year and admitted that the road ahead looked rough. Its stock plunged -- as did other electronics shares -- and the Nikkei Stock Average hit the lowest level in two decades. Some dubbed this the "Sony shock."

The spread of internet connectivity diminished the importance of TV broadcasts, CDs, DVDs and their corresponding playback devices. Digital innovation meant that, like PCs, televisions became little more than collections of semiconductors and other readily available components. This commoditization enabled low-cost Chinese and South Korean players to catch and surpass Japan's old-guard manufacturers.

Sony lost its sense of direction. It lagged behind Apple in blending software, hardware and online features in products that consumers would line up for. As the former executive lamented, Sony grew risk-averse. The more it tried to play it safe, the more it seemed to struggle.

But when Hirai took over, he vowed to "change" Sony. He wasn't kidding.

Hirai did not follow the typical path to the top. While electronics were always seen as the core of Sony, he made his name in the music business in the U.S. and the gaming division in Japan. This outsider status enabled Hirai to pursue audacious structural reforms in the money-losing electronics business, Nomura Securities analyst Yu Okazaki said.

With Hirai and Kenichiro Yoshida, the executive deputy president and chief financial officer, running the show, Sony has either sold or combined a host of businesses: small and midsize liquid crystal displays, chemicals, Vaio PCs, batteries and so on. It has scaled down its administrative section at the head office and cut some 10,000 jobs groupwide.

Through it all, Sony did manage to maintain strong earnings in the entertainment business -- including games, music, movies and TV shows.

The company's profit margin on music is improving thanks to the rise of subscription-based streaming services, which has expanded the market for recorded songs. Its latest video game console, the PlayStation 4, is a huge hit and could find an even wider audience when a virtual reality headset hits the market later this year. The hope is that the PlayStation could become the go-to platform for all kinds of VR content, not just games.

Meanwhile, by sharpening its focus on ultrahigh-definition 4K televisions, Sony brought its TV segment back into the black in fiscal 2014 for the first time in 11 years.

Now that the entire electronics segment is profitable again, Sony is ready to tackle the next challenge: innovating again.

MAKING CONNECTIONS The nascent AI and robotics initiatives are not simply about robots in the strict sense of the word. The idea is to establish a cutting-edge foundation for all products and services.

Sony is working on prototypes -- from earphones to desktop minirobots -- in search of the ideal AI interface. "We will develop AI platforms that can serve as the fundamental infrastructure for society and life in the future," Hirai said.

For the president, it is all about the "last 1 inch," or the point where people come in contact with the cloud and artificial intelligence.

Yoshida, the finance chief, is convinced all this will put Sony on a firm footing. "Connecting AI and robotics to a network," he predicted, "will create new services that will earn recurring revenue from stable customers."

Finally, after nearly two decades of focusing on what ails the company, executives are looking toward the future. MIT's Ito, for his part, believes that future is bright. "Sony has great potential," he told the Nikkei Asian Review. "You should expect a lot of the company."

Nikkei staff writer Shunsuke Tabeta and Nikkei Asian Review Editor-at-large Ken Koyanagi contributed to this article.