How to change an entry's slug on EVENT_AFTER_SAVE_ELEMENT?
You can change the value in the DB directly instead of using the Elements service

$entry = $event-&gt;element;
$elementId = $entry-&gt;id;
$siteId = $entry-&gt;siteId;
Craft::$app-&gt;getDb()-&gt;createCommand()
    -&gt;update(
        '{{%elements_sites}}',
        ['slug' =&gt; ElementHelper::createSlug('new-slug')],
        [
            'elementId' =&gt; $elementId,
            'siteId'    =&gt; $siteId
        ]
    )-&gt;execute();


By the way the following condition [] !== $entry won't be any good when you fetch an element with one() because one returns an object of instance ElementInterface or null but never an empty array. You can check !== null instead and if you fetch things via all you can perform an empty check if( empty($entries) === false)