The 9x18mm was originally based on the .380 (aka 9x17mm) Ultra that was developed towards the end of World War II. However, it was upsized some to prevent Western nations from being able to use captured ammo, hence its sizing at .362 instead of .357. The 9x18 round really is at the upper limits of what you can do with a direct blowback pistol like a PPK, Makarov, or similar. You can't put a full-sized 9mm round in one of those and have it be either pleasant to shoot or long-term reliable. It would just beat itself to death.
Russia wanted a firearm that was simple and cheap to produce, reliable, and accurate. They did not want to repeat their mistake with the Tokarev, which required tight tolerances to be accurate (which is why only a few countries' Tokarevs, Russia not included, were accurate). They took some inspiration from the Walther PPK, and improved upon it in creating the Makarov. Other countries followed suit and created their own 9x18 firearms, some based more on the PPK than others, though the Makarov itself is generally regarded as the best for features and trigger.