There's essentially one word, with two meanings and two spellings. Wikipedia has articles at Carat (purity) and Carat (mass). As a unit of mass, one carat (used for gemstones) is 200 g, and as a measure of purity, n-carat gold (n≤24) is n/24 gold by weight. (12-carat gold is 50% gold, etc.) The spellings carat and karat are spelling variants of the same term. In America, a convention has been adopted to use the spelling carat for mass, and karat for purity. While this is a very fine convention to avoid confusion between the two meanings, does this make them two different words?
Etymologically, the Online Etymology Dictionary says
mid-15c., from M.Fr. carat "measure of the fineness of gold" (14c.), from It. carato, from Arabic qirat "pod, husk, weight of 4 grains," from Gk. keration "carob seed," lit. "little horn" dim. of keras "horn." Carob beans were a standard for weighing small quantities. As a measure of diamond weight, from 1570s. The Gk. measure was the equivalent of the Roman siliqua, which was one-twentyfourth of a golden solidus of Constantine; hence the word took on a sense of "a proportion of one twentyfourth" and became a measure of gold purity (1550s). Eighteen carat gold is eighteen parts gold, six parts alloy. It is unlikely that the classical carat was ever a measure of weight for gold.
variant of carat (q.v.). In U.S., karat is used for "proportion of fine gold in an alloy" and carat for "weight of a precious stone."
So both the weight meaning and the 1/24th meaning come from Greco-Roman times (via Arabic, Italian, Middle French, in that order).
The Wikipedia sections Carat (purity)#Derivation and Carat (mass)#Etymology agree: once upon a time, carob seeds, because of their reputation for uniform weight, were used as measures of weight. This measure was roughly 1/24th of another unit, so the purity measure arose of it. There was no confusion because as weight, carat was probably never used for gold (and is today only used for diamonds, pearls, other gemstones).