And Ellie pushed him to see her as his new daughter for most of the journey despite Joel resisting it at first. But even if we ignore all that, despite of the "wrong" reason, he ended up doing something good.
Just because Joel still ends up being a selfish man, he does go through a pretty big arc, going from being a person completely detached from his emotions that pushes everyone away to finally accepting a bond with another person, to the point that he would doom the chance of a cure just to keep her alive and remain close to her.
I know people sometimes think character arcs are this thing where characters do a complete 180, but that's never reality. Joel's arc is actually one of the better, more realistic arcs I've seen in games. He's still Joel, but he definitely changes.