diff --git a/src/LinkExtractorService.php b/src/LinkExtractorService.php
index 1234567..abcdefg 100644
--- a/src/LinkExtractorService.php
+++ b/src/LinkExtractorService.php
@@ -371,6 +371,10 @@ class LinkExtractorService {
     $storage = $this->entityTypeManager->getStorage($link->getEntityTypeId());
 
     $parent_entity = $link->getParentEntity();
+    // If parent entity was removed, skip saving the link.
+    if ($parent_entity === NULL) {
+      return;
+    }
     $query = $storage->getQuery()->accessCheck(FALSE)
       ->condition('urlhash', LinkCheckerLink::generateHash($link->getUrl()))
       ->condition('parent_entity_type_id', $parent_entity->getEntityTypeId())