You might be remembering The Adventures of Hercules, the 1985 sequel to Hercules (1983). Both films star Lou Ferrigno in the title role, both are written and directed by Luigi Cozzi, and both include some science-fiction elements, but the 1985 outing is a bit more "spacey".

The premise of The Adventures of Hercules, from Wikipedia:
"The film opens explaining the story of Zeus' Seven Mighty Thunderbolts that kept peace. One day, other vengeful gods (Aphrodite, Hera, Poseidon, and Flora) stole these lightning bolts to create chaos. The lack of these thunderbolts has rendered Zeus powerless and sent the Moon on a collision course with the Earth."
Aspects that match your memory:
I remember a peblum / swords and sandals movie
Although overall it's perhaps science-fantasy, Hercules sports a loincloth and sandals, and primarily wields a sword. Other heroes likewise use non-technological weapons, such as bows and spears, sometimes magical.
where the protagonist (Hercules or whatever his name is)
Hercules is the protagonist.
eventually fights the main villain in space.
At the film's climax, Hercules and his nemesis, Minos, literally battle in space. As they do so, they transform first into rotoscoped "pure energy" versions of themselves, then Minos morphs into an energy T-Rex while Hercules becomes a neon gorilla.
They are fighting on the moon (or a different planet)
Minos has a base (well, a movie set) on the moon where he holds captive one of Hercules' companions, Urania. Just prior to the final battle, Minos transforms into a comet, flies from the moon to swoop around some asteroids, and confronts Hercules.
and the villain has many technological gadgets
Throughout the film, Minos is working with Dedalos (sic) to utilize "science" against Hercules. At various points, Minos shoots lasers from his eyes, has a kind of light sword, a forcefield, etc.
but in the end is no match for the main [hero].
As expected, Hercules prevails.
Trailer on YouTube