Gym battles serve as a testament to a player's skill in a Pokemon game. Overcoming a Gym Leader's team shows that a trainer has a better understanding of how the game works and how to utilize their own team of creatures well. Some of these Gym battles put trainers to the test, especially when they involve a bit more skill beyond remembering the type matchups and leveling up Pokemon.
However, the toughest Gym battles aren't always the ones that happen near the end of the game, as competent players will have a full team by that point capable of dealing with most threats thrown at them. Instead, a fair number of these Gyms are from the early-to-mid sections of the games.
Toughest Gym Battles in each Pokemon game
1) Sabrina (Red/Blue/Yellow/FireRed/LeafGreen/Let's Go Pikachu and Eevee)

🚨 Calculate how strong your evolved Pokémon will become with our newly launched Pokemon GO Evolution Calculator 🚨
Sabrina, the Psychic-type specialist in Kanto, being the strongest Gym Leader in Red, Blue, and Yellow, shouldn't surprise anyone even vaguely familiar with the overpowered nature of the Psychic type in Gen I. With no effective counters and access to Alakazam, the next best Psychic type after Mewtwo, the only way to face her was to brute force your way with Pokemon that have high Special stats.
However, the fact that she continues to be the strongest even in later Generations is truly impressive. This can be chalked up to the fact that the new Dark and Steel-type Pokemon introduced to check Psychics are very uncommon in Kanto. This allows the fight against Sabrina to be the strongest Gym Battle in any game set in Kanto.
2) Whitney (Gold/Silver/Crystal/HeartGold/SoulSilver)

Whitney has terrorized all players who have gone up against her in a Gym battle. While her Clefairy is... there, her Miltank gives her the reputation she has. At the time in the game when players face Whitney, Miltank's 100 base Speed lets her outspeed almost any other creature available.
This allows Miltank to flinch with Stomp, use Attract to immobilize male opponents, use Rollout to deal continuously increasing damage, and even recover with Milk Drink. It gets worse in HeartGold and SoulSilver, where Whitney's Miltank has the ability Scrappy to hit Ghost types and holds a Lum Berry to cure status once.
The only handful of counters to Whitney are either trading a Drowzee in Goldenrod City for a female Machop (to deal with Attract), tanking her attacks with a Rock-type like Geodude or Onix (Rock resists Normal) or headbutting trees for a Heracross in HeartGold and SoulSilver (it gets access to the Fighting-type move Brick Break).
3) Norman (Ruby/Sapphire/OmegaRuby/AlphaSapphire)

Norman is another Normal-type specialist who has given trainers a lot of trouble. Interestingly, thanks to Slaking's ability, Truant, players get a free turn to do whatever they want. However, on the turn that Slaking can attack, it deals massive damage courtesy of its amazing stats.
At this point in the game, the player's best option is to bring a Pokemon like Pelipper or Dustox that learn Protect by level up to attack and stall on consecutive turns.
4) Tate & Liza (Emerald)

In Pokemon Emerald, Tate and Liza appear as the hardest Gym battle in the game. These two exploit the new double battle mechanic by bringing a Xatu and Claydol, with the latter's Flying-type letting Claydol spam Earthquake without worry. While spamming Surf is still the best way to beat them, they are much tougher this time around.
5) Fantina (Diamond/Pearl/Platinum/BrilliantDiamond/ShiningPearl)

Fantina's place on this list comes down to the fact that she has a Mismagius with excellent coverage at a time when players just don't have enough options to counter her. As for her other two mons, while her Haunter/Gengar runs a physical set for some reason, her Drifblim/Duskull is annoying to deal with, thanks to utilizing evasion or burn tactics.
Players should try to invest in a Dark-type like Umbreon in Platinum or at least carry a mon that has access to Dark-type moves like Bite or Crunch, like Luxray or Floatzel.
6) Elesa (Black/White)

The Gym battle with Elesa in Black/White is a classic example of having few options to choose from. Her double Emolgas are part Flying, so bringing a Ground-type like Sandile or Drilbur won't help. Grass types like Servine and Simisage are weak to STAB Aerial Ace from those same Emolgas, as is the part Fighting Pignite.
As for players looking to brute force this fight through neutrally-typed Pokemon, her Emolgas and Zebstrika spam the move Volt Switch, which constantly deals damage while switching, slowly wearing them down. One of the few notable counters is Palpitoad (yes, Ash had the right idea in that gym battle); however, even with an Eviolite, it struggles to take on all three of Elesa's Pokemon.
7) Clay (Black 2/White 2)

Clay is on this list less on his own merits and more on the fact that the TM for Scald is no longer available right before his Gym battle. However, his team does have some merits, as thanks to Krokorok's Intimidate and the high Defense stat of Sandslash, his team shuts down physical attackers hard. The best way to deal with him is with a special attacker like Lilligant or Simipour.
8) Grant (X/Y)

Pokemon X and Y are not known for their difficulty. However, Grant can trip up some players during his Gym battle. This is because, unlike most Gyms, instead of an ace, he has two level 25 Pokemon — Amaura and Tyrunt. He leads with his Amaura, which tends to paralyze opponents with Thunder Wave and leave them vulnerable for Tyrunt to finish off.
While Fighting types like Hawlucha, Lucario, and Pancham should be able to win out eventually, a player could get unlucky with a paralysis turn at the wrong moment.
9) Totem Lurantis (Sun/Moon/UltraSun/UltraMoon)

While there aren't any Gyms in the Alola games, the battle against Totem Lurantis certainly qualifies. Starting with a +2 Speed boost, this Lurantis can fire off a Solar Blade (usually a two-turn move) on the first turn thanks to its held Power Herb. It can then call allies like Castform in Sun/Moon, who can set up the sun again for single-turn Solar Blades or greater healing with Synthesis.
The best way to counter this menace is by bringing a Crobat who resists all of Lurantis' moves thanks to its Poison/Flying typing. Other Pokemon, even Fire types and other Poison types tend to be worn down quickly.
10) Raihan (Sword/Shield)

Raihan's Gym battle is the only 8th Gym to make it on this list. But there's no doubt he earns it owing to his unique strategy — a double battle with a team utilizing sandstorm. Each of his team members is immune to sand while it chips away at the opponent. This means that good counters to his team like Haxorus, Alcremie, and Gyarados will be put on a timer as they are whittled away when on the field.
11) Iono (Scarlet/Violet)

Iono's Gym battle is difficult because of her ace Mismagius. Unlike Fantina's poltergeist, Iono's Mismagius has only Electric and Ghost moves. What put her on the list was that after Terastallizing into an Electric-type, her Mismagius doesn't have any weaknesses thanks to her ability Levitate giving her a Ground immunity.
As players would struggle to brute force past such an opponent if their Pokemon were the same level as Iono's, she earns her place as Paldea's toughest Gym leader.