Oh, brother ... it's incredible that the STAR TREK producers never tired of this storyline. It goes: a group of (often renegade) super-powered aliens defeat the crew and take possession of the Enterprise in order to conquer the universe/return home/open a fast food franchise. Luckily, recourceful Kirk figures out a way to defeat the aliens, by using superior Earthman logic/illogic/cooking skills. Once the aliens are defeated, Spock admires Kirk's use of logic and McCoy finds time for just one more insult on Spock before everyone chuckles and the final credits roll.
What's more astonishing is that the episode is credited to sf writer Jermoe Bixby (also responsible for the fabulous "Mirror, Mirror" episode). I can only assume that Gene Coon did a heavy re-write in order to make this conform to his idea of the perfect ST episode (though it's my idea of the worst!)