diff --git a/core/modules/media/src/Entity/Media.php b/core/modules/media/src/Entity/Media.php
index 2170f91979bd811d4b72f182dfeaa7023d5869c9..415b19cc88c8cdf422e55aff97113d24cca74ced 100644
--- a/core/modules/media/src/Entity/Media.php
+++ b/core/modules/media/src/Entity/Media.php
@@ -297,6 +297,10 @@ protected function shouldUpdateThumbnail($is_new = FALSE) {
   public function preSave(EntityStorageInterface $storage) {
     parent::preSave($storage);
 
+    if (!$this->getOwner()) {
+      $this->setOwnerId(0);
+    }
+
     // If no thumbnail has been explicitly set, use the default thumbnail.
     if ($this->get('thumbnail')->isEmpty()) {
       $this->thumbnail->target_id = $this->loadThumbnail()->id();
diff --git a/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php b/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php
index 5446c3a3ca7ed586749f2c245f670824e20d229e..362467b3807ca354d7b3abd428dea67491709c02 100644
--- a/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php
+++ b/core/modules/media/tests/src/Functional/MediaUiFunctionalTest.php
@@ -92,6 +92,21 @@ public function testMediaWithOnlyOneMediaType() {
       ->loadUnchanged($media_id);
     $this->assertSame($media->getName(), $media_name2);
 
+    // Change the authored by field to an empty string, which should assign
+    // authorship to the anonymous user (uid 0).
+    $this->drupalGet('media/' . $media_id . '/edit');
+    $edit['uid[0][target_id]'] = '';
+    $this->submitForm($edit, 'Save');
+    /** @var \Drupal\media\MediaInterface $media */
+    $media = $this->container->get('entity_type.manager')
+      ->getStorage('media')
+      ->loadUnchanged($media_id);
+    $uid = $media->getOwnerId();
+    // Most SQL database drivers stringify fetches but entities are not
+    // necessarily stored in a SQL database. At the same time, NULL/FALSE/""
+    // won't do.
+    $this->assertTrue($uid === 0 || $uid === '0', 'Media authored by anonymous user.');
+
     // Test that there is no empty vertical tabs element, if the container is
     // empty (see #2750697).
     // Make the "Publisher ID" and "Created" fields hidden.