Based on my own experiences as a member on several live audiences and from discussions with a friend who is a writer and producer ...
The audience is explicitly told that they need to react to re-takes as if you hadn't already heard the joke.
Don't flub the lines. Most sitcom actors are also stage actors, used to live theatre. Direction, timing, and blocking have all been worked out in rehearsals, and, with three or four simultaneous cameras, you've got some flexibility to cut around minor technical mistakes. There may not be as many retakes as you might expect.
A warm-up comedian keeps the audience energy level up between scenes or other delays.
Don't go long. A half-hour comedy, when all goes well, keeps the audience only 60-90 minutes.
Feed the audience sugar. Often, before the last scene of the show, the ushers will give out candy bars so that the audience members have a burst of blood sugar right as they're capturing that final joke.
Laugh tracks are "sweetened." They can blend (mix) the live audience reaction with their reactions from other takes (or even other parts of the show). They can also mix in guffaws and laughter from libraries of audience recordings.
Change the joke. On some shows, the writers are on set during the taping, will gauge the audience reaction and provide alternate punchlines, so the re-take is familiar but has a fresh punchline.
Cut the joke. I once watched an actor get tongue tied again and again on the punchline for a throwaway joke from a sitcom opening. After eight or so retakes, they just switched to shooting another joke (which I think was written for a future episode). Later, I saw the original joke attached in a different episode.
Hide the reveal. This isn't so much about retakes but about jokes based in the sudden visual revelation of a situation. For example, you see the character in bed talking to whom you assume is their spouse, then the camera pulls back and you see they're actually talking to their pet. I've seen this done by blocking the live audience's view of the set with a curtain and having them watch the restricted camera view on monitors. At the moment the camera pulls back to reveal the Saint Bernard on the bed, the curtain is dropped so that the laugh it timed just right.
Pre-shoot technically difficult scenes. Sitcoms are generally shot in sequence for the benefit of the audience. Old shows used to keep almost all of the action on one or two sets that fit in front of an audience. Modern shows might have a dozen sets, outdoor shots, montages, and even complex visual effects shots that make it impractical to shoot everything in front of the audience. So the hard bits are pre-recorded and edited. The audience is shown the pre-recorded sequences on monitors and their laughter is recorded. No retakes there.
Improvise.
Long ago, I saw a shooting of Cheers. They were doing an episode and a half in one night, in order to make up for a holiday. The first episode started more than an hour late. And that was with the tongue twister opening joke that they punted after many takes. Lots of little things went wrong, so there were extra delays. By the final scene of the full episode, the audience energy was fading. And, for reasons I don't recall, they kept doing takes. Hardly anyone laughed. The warm-up comic tried everything. The last joke involved Norm (George Wendt) and Cliff (John Ratzenberger), we'd already heard it many times, some in the audience were literally asleep. So, in that last take, just at the punchline we all already knew by heart, John Ratzenberger started riffing--in character--telling raunchy jokes, making up hilarious stuff. This got the audience's attention. The audience, the crew, and the cast were all laughing hard. Then Ratzenberger pointed at the director, said "keep rolling", and he delivered the scripted line.
By the time they finished the first episode, it was approaching 11 PM. They wanted us to stay for the first half of the next episode. But many of the audience members trickled out. The sound people had the ushers consolidate the audience into one quarter of the seating area in order to concentrate our laughter in one audience microphone and they shut off the rest. They sent up more candy bars.
They started the second episode and everything went fine. Then there was a break for a costume change, and everything ground to a halt. For a very, very long time. At last, they shot another scene, that--if I recall--didn't even involve the character with the unusual costume. In the scene, there was an after-hours party in the bar, so there were these catering trays with sandwiches all over the set. As soon as the scene was over, the director sent the sandwiches up to the dozen or so of us still in the audience, clearly a bribe to keep us awake and laughing. At last, we saw the midpoint scene. I don't think we got off the lot until after 1 AM.