Did Joel lie at the end of the game? If so, why?
Did Joel lie to Ellie?
Yes, Joel lies to Ellie. This is made clear by the flashbacks that you see while he is telling her the story when she wakes up in the car.
He says that the Fireflies have found many people who are immune to the fungus and that they have stopped looking for a cure. This is clearly not true as he had to forcefully extract Ellie from the operating room before the medical team could kill her to extract the cure from her.
The fact that this is a lie is also underlined by the flashback involving Marlene: She tried to stop Joel in the parking lot when he was carrying Ellie to the car to get away with her. Joel had to shoot her to be able to leave with Ellie.
Why did Joel lie to Ellie?
This is mostly speculation on my part based on the events of the game, but I think there are two reasons why Joel lies to Ellie.
Ellie is determined to finish her "mission".
Over the course of the game, there are several dialogues showing that Ellie wants to finish her mission. When they find the giraffes at the bus stop, Joel tells Ellie that she does not need to go through with all of this but she insists on going on:
After all we've been through. Everything that I've done. It can't be for nothing. Look, I know you mean well … but there's no half-way with this.
After arriving at the Fireflies, Marlene asks Joel how they managed to get to them and he emphasizes that it was Ellie's wish:
Marlene: You came all this way… How'd you do it?
Joel: It was her. She fought like hell to get here.
The final dialogue in the game showcases how torn Ellie is about not being able to fulfill her mission to help create a cure. Her struggle is obvious in how she opens the conversation with Joel:
Ellie: Hey, wait. (long pause, deep sigh)
She goes on to explain how she got infected and where her internal struggle originated:
Ellie: Back in Boston - back when I was bitten. I wasn't alone. My best friend was there. And she got bit too. We didn't know what to do. So... She says, "Let's just wait it out. Y'know, we can be all poetic and just lose our minds together". I'm still waiting for my turn.
Joel: Ellie…
Ellie: Her name was Riley and she was the first to die. And then it was Tess. And then Sam.
My interpretation is that Joel is and has been for quite a while fully aware of this struggle going on inside Ellie. Maybe not to the full extent she is describing here, but sufficiently aware that this will have impacted his decision to not tell her the truth. He goes on to share his own experience and tries to make her feel better about it:
Joel: None of that is on you.
Ellie: You don't understand.
Joel: I struggled for a long time with survivin'. And you… (touches the watch his daughter Sarah gave him before she died) No matter what, you keep finding something to fight for.
The severity of Ellie's struggle is underlined by the backstory told in the "The Last of Us: Left Behind" DLC. It shows how close Ellie and Riley were just before they were bitten. They had just shared their apparently first kiss with each other. To make matters worse, Ellie is probably blaming herself for getting Riley and herself infected. As they were escaping from the Infected, Riley had already escaped to higher ground but went back down to help Ellie who fell while trying to follow her. They both subsequently got bit.
Joel does not want to lose Ellie
Even though Joel always tries to pretend that Ellie is just annoying him, there are hints early on that Ellie reminds him of his daughter, Sarah, who died at the beginning of the outbreak. The first subtle hint is given in a cutscene shortly before they arrive at the Capitol building. Joel and Ellie have a short conversation about the beauty of the view from a rooftop, at the end of which Joel looks absently at the watch Sarah gave him.
Towards the end of the game it becomes clear that they have bonded. The conversational tone between them changes remarkably over the course of the game. This can be seen by a conversation that takes place relatively early in the game shortly after Tess has died and Joel and Ellie have escaped the soldiers:
Joel: And lastly, you do what I say, when I say it. We clear?
Ellie: Sure.
Joel: Repeat it.
Ellie: What you say, goes. sighs
Joel: sighs Good.
Ellie clearly shows that she is attached to Joel when he is about to leave her with Tommy. She gets very worked up about this on the ranch she fled to:
Admit that you wanted to get rid of me the whole time!
Joel is trying to justify his decision rationally but Ellie does not want to hear it:
Everyone I have cared about has either died or left me. Everyone — fucking except for you! So don't tell me I would be safer with somebody else, because the truth is I would just be more scared.
In the end, Joel goes with her even though he pretends he only does it to not upset Tommy's wife who did not want Tommy leaving the family to help Ellie.
Joel's growing affection to her is expressed subtly over the course of the game and climaxes for the first time when he finds her hacking on David in the burning restaurant. He hugs and comforts her and she accepts the comforting. This is also the first time I consciously saw him calling her "baby girl". Note that the only other person he has called "baby" so far was his daughter Sarah.
Ellie is hacking on David's head with a switchblade.
Joel: Ellie! Stop. Stop. grabs her and pulls her off David
Ellie: not realizing who is coming No! Don't fucking touch me!
Joel: holds her It's okay. It's me. It's me. It's me. Look, look. turns her head to face him It's me.
Ellie: sobbing He tried to…
Joel: hugs her tight, comforts her Oh, baby girl… It's okay. It's okay. It's okay now.
The second time he calls her "baby girl" is when he is carrying unconscious Ellie out of the operating room before the doctors can kill her:
Come on, baby girl. I got you. I got you.
This scene also reminds the player of the last moments of Sarah's life, when he was carrying her while running away from infected people who want to kill them. Now, he is carrying Ellie while escaping from the Fireflies who want to kill them. Once he is out of there, he even shoots Marlene who begs for her life to keep Ellie safe:
You'd just come after her.
All of this suggests that he is by the end deeply attached to Ellie and very afraid of losing her.
Conclusion
The conclusion of these two reasons is that Joel has no other choice but to lie to Ellie. If he had told her the truth she probably would have gone back to the Fireflies to finish her mission and die so they could extract the cure from her.
Even if Joel had managed to prevent her from leaving she would have despised him for taking away her chance to redeem her guilt. This would have made it very difficult to maintain a healthy relationship with her.
It is left unclear whether Ellie actually believes the lie. The game ends on a very doubting looking Ellie suggesting that she knows she is being lied to. My interpretation is that she knows but also sees that Joel is very attached to her and understands why he lies. Maybe his words in their final conversation also moved her to let go of her initial mission to help find the cure.
Joel: I struggled for a long time with survivin'. And you— No matter what, you keep finding something to fight for.
Ellie's well being gives Joel's life meaning and purpose, something to fight for. At the same time, Ellie feels responsible for Joel, realizing that even though he pretended otherwise in the past, she is very important to him, to a certain extent replacing the daughter he lost. Essentially, they have become each other's "raison d'être".
Yes, Joel lied to Ellie about the Fireflies. The motivation of the lie isn't clearly stated and up to speculation.
One could argue that he either saw Ellie as his daughter and did not want to lose her again no matter the consequence or he did not accept the sacrifice of a child as a valid approach to cure humanity.