SANTA CLARA, Calif. — Jim Harbaugh got doused with a celebratory shower after his final game coaching the San Francisco 49ers, then said his goodbyes with handshakes and hugs all around.

Colin Kaepernick confidently declared he’s still the quarterback capable of leading this team back to the Super Bowl. Frank Gore cried, contemplating what might have been his last game in a Niners uniform.

In a bizarre finish to a most bizarre season, San Francisco beat the Arizona Cardinals 20-17 on Sunday and avoided ending on a losing note and with a losing record in a year that began with Super Bowl aspirations.

“I’m forever proud to have been a part of this,” Harbaugh said. “It’s been a tremendous four years; it’s been a pleasure to work and serve for this organization.”

Kaepernick threw a go-ahead 3-yard touchdown pass to Bruce Miller late in the third quarter and Gore capped another 1,000-yard season with 144 yards on 25 carries.

Anquan Boldin caught a 76-yard TD pass and went over 1,000 yards receiving. Gore reached 1,000 yards rushing for the eighth time in 10 NFL seasons with the 49ers (8-8). The franchise’s all-time rushing leader hopes to return to the only team he has known and the team has expressed a mutual interest.

Harbaugh and the 49ers reached a mutual agreement to part ways, but he wouldn’t say what is next.

“It’s bittersweet,” Kaepernick said. “Coach Harbaugh’s the coach that drafted me, he’s the coach that chose to start me, he’s the coach that stood behind me through everything.”

Harbaugh departs with one season remaining on the $25 million, five-year contract he signed in January 2011. He led the 49ers (8-8) to three NFC title games and one loss in the Super Bowl.

Asked whether it was his choice to move on, Harbaugh said, “You work at the pleasure of the organization, that’s what we all do.”

Harbaugh sprinted off the Levi’s Stadium field for the final time, cradling the game ball.

Harbaugh spoke briefly on the field to CEO Jed York before the game amid unconfirmed reports the coach is bound for Michigan. Harbaugh said “announcements” will be made.