The year was 2012, and everything seemed to be going wrong for Best Buy.

The CEO had just resigned after admitting to an improper relationship with a female employee. Employee engagement seemed to be at an all-time low. And like many other retailers, Best Buy stores were bleeding money--as customers came to test products they wanted, only to buy them online from Amazon at a cheaper price.

Best Buy was dying a slow death.

But fast forward to today, and the company is thriving: The company just released its latest results, which beat analysts' expectations. Comparable store sales continue to rise, the stock price is surging, and workers seem happier than ever.

So, how did Best Buy do it?

A look back at the company's actions over the past few years reveals a brilliant combination of corporate strategy and emotional intelligence.

Here are some things that stick out:

1. Focus on people.

When Hubert Joly took over as Best Buy's chief executive in 2012, he knew he had to tap into his people if the company had a shot at surviving. So, in his first months on the job, Joly did something great: He visited Best Buy stores (and even worked at a store for a week), giving him the chance to speak directly to front line employees.

Based on their feedback, Joly:

fixed broken systems, like an internal search engine that gave bad data about which products were in stock;

restored a beloved employee discount program; and

invested heavily into regular employee training.

The measures seem to have worked.

According to workplace review website Glassdoor, 78 percent of employees would recommend working at Best Buy to a friend, and Joly enjoys a 92 percent employee approval rate. (Compare that with fellow retailer Walmart's figures, with only 55 percent of employees who would recommend working at their store to a friend and 65 percent approval of the CEO.)

2. Turn weakness into strength.

Joly was well familiar with the practice of "showrooming," in which customers came into a store to test products before buying online from competitors. So, he used that practice to his advantage--by instituting a price matching system.

This was a bold move that critics said would cannibalize more expensive sales. But the strategy made sense because it took advantage of the fact that customers want to see expensive items like a big-screen TV or smartphone up close before they buy. If the store is willing to price match, why not buy then and there?

"Until I match Amazon's prices, the customers are ours to lose," Joly told the New York Times.

The company also figured out how to make showrooming work for its advantage. It made deals with large electronics companies (like Apple and Samsung) to feature their products. In essence, these companies rent square footage within Best Buy to feature all their products together in a branded space, which gave Best Buy access to a new revenue stream.

Additionally, Joly and his team made changes that allowed stores to serve as mini warehouses for online customers. That means customers can order a product online, then choose whether to pick it up or have it shipped. This allows Best Buy to compete even better with you-know-who.

3. Don't sell. Build relationships.

There was one advantage Best Buy already held over Amazon and other online retailers: the ability to connect with customers.

The company's Geek Squad, a group of especially trained tech support experts, were popular with many. But Joly and Co. went a step further by starting an In-Home Advisor program. Through this program, Best Buy sends consultants to the privacy of your own home to offer advice and help you decide if and what you'd like to purchase.

"Advisors" are encouraged to establish long-time relationships with customers, rather than chase sales. In fact, according to a Bloomberg report, In-Home Advisors don't need to track weekly metrics and are paid an annual salary instead of an hourly wage. House calls are free, can last up to 90 minutes, and advisors are told to "be comfortable not closing a deal by day's end."

These are just a few of the things Best Buy has done to stay relevant, and avoid falling victim to the retail apocalypse. But in the end, Joly realizes he doesn't need to defeat Amazon. Just co-exist with it.

"You won't get me to say a bad word about Amazon," Joly said. "It's not a zero-sum game."