Gel electrophoresis separates DNA fragments by size by running an electric current through an agarose gel, causing the negatively charged DNA fragments to migrate towards a positive electrode. Smaller fragments move faster through the gel's pores than larger fragments, allowing DNA fragments to be visualized based on their relative sizes after a period of time.