Going into detail on other languages is beyond the scope of this site, but, it's not just English. You can use the term "lexical stress" to look up examples of languages where two words can differ in stress and nothing else: many languages with lexical stress have stress patterns based on how a word is put together. Other examples are Russian, Spanish, and Italian. (E.g. in Spanish the first-person singular present tense suffix -o in the verb canto doesn't take stress, but the third-person singular future tense suffix -ó in cantó does take stress.)
Old English stress was somewhat lexical, but more predictable than modern English stress. Old English did not have stressed or stress-attracting suffixes; instead, suffixes were unstressed and stress regularly fell on the first syllable of a root (roots were mostly monosyllabic, but some had unstressed second syllables). So when a word was built on one root plus one or more suffixes, the stress fell on the first syllable.
Compounds and prefixes are where things get a little bit more complicated. Old English had a few unstressed prefixes such as ge- and be-. But it also had stressed prefixes. Some prefixes (mainly ones derived from prepositions) could be either stressed or unstressed, depending on the grammatical structure of the word in which they occurred.
Old English also had noun-noun compounds (among other types of compounds), and as in modern English, the main stress in compounds fell on the first root.
The modern English stress system (where there are suffixes like -ic(al) that appear to have the power to attract stress to a preceding syllable) is derived from reinterpretation of the stress patterns of words inherited from English alongside words derived from Latin and the Romance languages that had stress in other positions. The latter set of words entered English mainly in the Middle English period (older loans were adapted more to the Old English stress patterns.) Some analyses of English stress still treat it as having separate and somewhat distinct "systems" for assigning stress to words, although it's unclear if this is really accurate except as a historical explanation. (The suffix -ly is supposed to belong to the system of non-stress-affecting suffixes, but many speakers stress different syllables in necessary and necessarily).