diff --git a/entityqueue.module b/entityqueue.module
index 7a3efc8..c0bc94d 100755
--- a/entityqueue.module
+++ b/entityqueue.module
@@ -6,9 +6,12 @@
  */
 
 use Drupal\Core\Access\AccessResult;
+use Drupal\Core\Entity\EntityInterface;
 use Drupal\Core\Field\FieldDefinitionInterface;
 use Drupal\Core\Field\FieldItemListInterface;
 use Drupal\Core\Session\AccountInterface;
+use Drupal\entityqueue\Entity\EntityQueue;
+use Drupal\entityqueue\Entity\EntitySubqueue;
 
 /**
  * Implements hook_entity_field_access().
@@ -96,3 +99,36 @@ function entityqueue_get_entityqueue_sort($view) {
   }
   return FALSE;
 }
+
+/**
+ * Implements hook_entity_delete().
+ */
+function entityqueue_entity_delete(EntityInterface $entity) {
+  $type = $entity->getEntityTypeId();
+  $bundle = $entity->bundle();
+  $id = $entity->id();
+
+  // Get all the entity queues referencing the targets entity type.
+  $queues = EntityQueue::loadMultipleByTargetType($type);
+  foreach ($queues as $queue) {
+    $entity_settings = $queue->getEntitySettings();
+
+    // Check if the queue's bundle also matches that of the target entity.
+    if (in_array($bundle, $entity_settings['handler_settings']['target_bundles'])) {
+      // Get subqueues.
+      $query = \Drupal::entityQuery('entity_subqueue')->condition('queue', $queue->id());
+      $result = $query->execute();
+      $subqueues = EntitySubqueue::loadMultiple($result);
+
+      // Check if the entity is referenced in a subqueue.
+      foreach ($subqueues as $subqueue) {
+        $items = $subqueue->get('items')->getValue();
+        if (($item_key = array_search($id, array_column($items, 'target_id'))) !== FALSE) {
+          unset($items[$item_key]);
+          $subqueue->set('items', $items);
+          $subqueue->save();
+        }
+      }
+    }
+  }
+}
