I feel like the moral dilemma would have been even more profound if we didn't have to contend with the infected. Others have said that even if the doctors did create a vaccine the world would still have to deal with hundreds of thousands of infected running around, which could be a mark in favor of Joel's decision.
But hypothetically, if the virus was simply a pandemic that was killing off the population instead of turning them into "zombies" for lack of a better term, then really the only problem with distributing the vaccine would be the power struggle between the government and the Fireflies. Therefore Joel squandering the chance for a possible cure would have been that much more devastating to humanity's survival.
Nevertheless, we must put ourselves in Joel's position. If you think about it, there's only two people left in the world that Joel cares about: his brother and Ellie. And clearly, his relationship with his brother is strained. In Ellie, Joel has found something to live for, a happiness and contentment that fills the void that losing his daughter created. A void that neither Tommy nor Tess could fill. Only Ellie could. So in the end, when he realizes he could lose Ellie, he is afraid. Afraid of losing a another daughter and being alone. He doesn't care about anything else, any repercussions of his actions, and in that moment given Joel's past, and his relationship with Ellie, there is no other option.