Use the \Magento\Config\Model\ResourceModel\Config::saveConfig() method:
\Magento\Config\Model\ResourceModel\Config::saveConfig()
An example of usage from the core: