The letter G was invented in the 3rd century BC by a Roman named Spurius Carvilius Ruga.

He derived it by adding a vertical stroke to the end of the letter C, and put it alphabetically in the place formerly occupied by Z, which is why the Greek has 'EZH' where Latin has 'EFGH'. (For what happened to F, see the history of digamma.)

The letter had to be invented because the Etruscans--who borrowed the alphabet from the Greeks and gave it to the Romans--didn't have the sound of G. They used C (Greek gamma), K (Greek kappa), and Q (Greek qoppa) for their K sound, so when the alphabet got transferred to Latin, a new letter was necessary for its voiced velar G.