Jim Harbaugh stood in the 49ers’ palatial locker room — one he helped get built — soaking up his final minutes as the team’s head coach, making goodbyes with reporters and hugging players.

General manager Trent Baalke — the victor in a lengthy power struggle — sat in a chair in a glassed-in office on the opposite side of the locker room, talking to the 49ers’ media-relations director.

Jed York? No sign of the team CEO and acting owner. Except on TV monitors, where his smiling face was pasted alongside a quote explaining that the 49ers had “mutually agreed to part ways,” with the best head coach the team has had in two decades.

“Jim and I have come to the conclusion that it is in our mutual best interest to move in different directions,” York said in a statement that was released to the media just moments after Harbaugh finished his postgame comments.

Mutual best interest? We’ll find out. Harbaugh’s future seems to be at his alma mater in Ann Arbor, Mich. Reports had him flying by private jet to the University of Michigan on Monday, where he will return to the college ranks and try, following the path of his mentor, Bo Schembechler, to restore Michigan to its past glory. For a reported salary of $8million a year.

And the 49ers? Their future remains to be seen. Harbaugh is only the second head coach in 49ers history, joining George Seifert, to avoid having a losing season. Harbaugh finished with a record of 49-22-1.

“Forty-nine wins — that’s appropriate,” Harbaugh said with a smile.

The 49th came Sunday, when the 49ers rallied to beat the Arizona Cardinals 20-17. Harbaugh was rewarded with a game ball, a Gatorade shower and the knowledge that he had won consistently with a team that had endured eight non-winning seasons before his arrival in January 2011.

‘Best years’ for many

“My best years have been with him,” said Frank Gore, who joined the 49ers in 2005. “We won.”

They did. More than at any time since the dynasty years.

Vince Lombardi was wrong. Winning isn’t everything. Winning isn’t the only thing. Egos and power struggles and personality conflicts are the only things that apparently matter, at least with the 49ers.

The 49ers’ failure to make the playoffs was convenient for York and Baalke, but Harbaugh’s ouster has been in the works for many months, long before the losses and theinjuries began to mount. That was clear from the on-going leaks to the national media about Harbaugh’s difficult personality, about where his future might be and how this was likely his last season.

There’s no doubt that Harbaugh is a challenging personality. Probably always has been, by his admission. A few years ago, when noting how beloved his older brother John was, Harbaugh said this about himself:

“I was always glad when my dad would take a job and move somewhere else, because by the time I went through there, I’d pretty much worn out my welcome.”

Harbaugh stayed at the University of San Diego three years, at Stanford for four years and, now, with the 49ers for four years. Which means Michigan probably shouldn’t start projecting plans for 2019.

But he is a winning coach. No one should know better than Jed York — son of John and Denise DeBartolo York — how difficult it is to come by a winning coach. Jed’s parents couldn’t find one for eight seasons after discarding Steve Mariucci because of a personality conflict.

Wired to succeed

Successful NFL coaches tend to be outsized, abrasive, slightly crazy personalities, with a single-minded focus. And that is Harbaugh.

Observers might not always agree with his methods or decisions. Discarding Alex Smith in favor of Colin Kaepernick was a bold decision. Insisting Aldon Smith and Ray McDonald play despite their legal problems was troubling to many. By many accounts, Harbaugh’s players grew weary of his tactics at times.

But there was no controversy about his results. He hired a strong staff, coached up his players and won. Yes, this season fell short of Super Bowl expectations, but that happens in the NFL.

Harbaugh did not change: He’s the same person York and Baalke pursued and hired four years ago. The 49ers have changed: from an inept franchise to one that thinks it has all the answers.

Before this season, the 49ers had made the playoffs three years in a row. Baalke was being lauded as a top general manager and York as a young owner who knows what he’s doing. They got their stadium built and are making money by the blimp load.

However, Harbaugh was instrumental in much of that change. In making Baalke and York look smart. In coaching up the players — the very best of whom were drafted before Baalke took control. In changing a culture so that it was attractive to sponsors who couldn’t wait to link their name to the team. In restoring the faith of fans who believed the team would win another Super Bowl and paid top dollar for tickets and seat licenses.

Above the fray

Will Harbaugh be content in college, recruiting teenagers, kissing up to boosters, following arcane rules? Most of us expected him to not rest until he matched brother John with a Lombardi Trophy. But Jim Harbaugh, too, might have tired of the drama and back-biting. To his credit, he didn’t participate in the leaks or undermining.

He simply ignored things he didn’t like and went on — single-mindedly — about the business of coaching.

“It’s been,” Harbaugh said, “the time of my life.”

And perhaps, of the current 49ers’.

Ann Killion is a San Francisco Chronicle columnist. E-mail: akillion@sfchronicle.com Twitter: @annkillion

49ers’ announcement

Owner Jed York and general manager Trent Baalke will hold a news conference at 1 p.m. Monday to address cutting ties with Jim Harbaugh and the organization’s subsequent coaching search. A newss release from the team contained these quotes by York and Harbaugh:

York: “Jim and I have come to the conclusion that it is in our mutual best interest to move in different directions. We thank Jim for bringing a tremendous competitive nature and a great passion for the game to the 49ers. He and his staff restored a winning culture that has been the standard for our franchise throughout its history. Their commitment and hard work resulted in a period of success that should be looked back on proudly by our organization and our fans. We wish Jim and his family all the best.”

Harbaugh: “For the last four seasons, I have had the great privilege to coach one of the storied franchises in the history of football. We accomplished many great things together as a team during this period, which is a tribute to the incredible efforts of some of the most dedicated players and coaches in the NFL. I will miss competing alongside this group of players and coaches, I have the utmost respect and admiration for their hard work and support. It has been my honor to share the sideline with these mighty men. I will always appreciate and remember fondly, the passion and support of our Faithful fans, and want to express my particular thanks to them.”

York: “We are now squarely focused on finding the next head coach of the 49ers and I am very confident in Trent’s ability to lead that process. With the great leaders and talented players we have in our locker room, we are ready to move into the next chapter of our team’s history.”