diff --git a/typo3/sysext/core/Classes/DependencyInjection/ListenerProviderPass.php b/typo3/sysext/core/Classes/DependencyInjection/ListenerProviderPass.php
index 0651172eec30e49d3a1464cf76b0f686b9d406b5..aef2b63e920089a50fd643baa7c2758ac8a4431a 100644
--- a/typo3/sysext/core/Classes/DependencyInjection/ListenerProviderPass.php
+++ b/typo3/sysext/core/Classes/DependencyInjection/ListenerProviderPass.php
@@ -59,11 +59,12 @@ final class ListenerProviderPass implements CompilerPassInterface
 
         foreach ($unorderedEventListeners as $eventName => $listeners) {
             // Configure ListenerProvider factory to include these listeners
-            foreach ($this->orderer->orderByDependencies($listeners) as $listener) {
+            foreach ($this->orderer->orderByDependencies($listeners) as $listenerIdentifier => $listener) {
                 $listenerProviderDefinition->addMethodCall('addListener', [
                     $eventName,
                     $listener['service'],
                     $listener['method'],
+                    $listenerIdentifier,
                 ]);
             }
         }
diff --git a/typo3/sysext/core/Classes/EventDispatcher/ListenerProvider.php b/typo3/sysext/core/Classes/EventDispatcher/ListenerProvider.php
index d67de06935691581e39db81ac0b4deca93a82a0e..6abda1e412ebc0b182ad7c2a4b1f94eb3bf8ae34 100644
--- a/typo3/sysext/core/Classes/EventDispatcher/ListenerProvider.php
+++ b/typo3/sysext/core/Classes/EventDispatcher/ListenerProvider.php
@@ -49,9 +49,9 @@ class ListenerProvider implements ListenerProviderInterface
      * @param string|null $method
      * @internal
      */
-    public function addListener(string $event, string $service, string $method = null): void
+    public function addListener(string $event, string $service, string $method = null, string $identifier = null): void
     {
-        $this->listeners[$event][] = [
+        $this->listeners[$event][$identifier ?? $service] = [
             'service' => $service,
             'method' => $method,
         ];
diff --git a/typo3/sysext/core/Tests/Unit/DependencyInjection/ListenerProviderPassTest.php b/typo3/sysext/core/Tests/Unit/DependencyInjection/ListenerProviderPassTest.php
index 1e749df8d9a5a06a3c46109006a70135832dd373..0465108eec328f46e145d21f8ed642532476938f 100644
--- a/typo3/sysext/core/Tests/Unit/DependencyInjection/ListenerProviderPassTest.php
+++ b/typo3/sysext/core/Tests/Unit/DependencyInjection/ListenerProviderPassTest.php
@@ -68,17 +68,17 @@ final class ListenerProviderPassTest extends UnitTestCase
         self::assertEquals(
             [
                 'TYPO3\\CMS\\Core\\Mail\\Event\\AfterMailerInitializationEvent' => [
-                    [
+                    'package2.listener' => [
                         'service' => 'package2.listener',
                         'method' => 'onEvent',
                     ],
-                    [
+                    'legacy-hook' => [
                         'service' => 'package1.listener1',
                         'method' => null,
                     ],
                 ],
                 'TYPO3\\CMS\\Core\\Foo\\Event\\TestEvent' => [
-                    [
+                    'legacy-hook' => [
                         'service' => 'package3.listener',
                         'method' => null,
                     ],
diff --git a/typo3/sysext/core/Tests/Unit/EventDispatcher/ListenerProviderTest.php b/typo3/sysext/core/Tests/Unit/EventDispatcher/ListenerProviderTest.php
index 9ed8683f02c96b1d58b0cdf791d8ec3d7921b8ab..d6e94d5467db5663c60f9b7466ce38efefe5fc33 100644
--- a/typo3/sysext/core/Tests/Unit/EventDispatcher/ListenerProviderTest.php
+++ b/typo3/sysext/core/Tests/Unit/EventDispatcher/ListenerProviderTest.php
@@ -55,8 +55,24 @@ final class ListenerProviderTest extends UnitTestCase
 
         self::assertEquals([
             'Event\\Name' => [
-                [ 'service' => 'listener1', 'method' => null ],
-                [ 'service' => 'listener2', 'method' => 'methodName' ],
+                'listener1' => [ 'service' => 'listener1', 'method' => null ],
+                'listener2' => [ 'service' => 'listener2', 'method' => 'methodName' ],
+            ],
+        ], $this->listenerProvider->getAllListenerDefinitions());
+    }
+
+    /**
+     * @test
+     */
+    public function addedListenerCorrectlySetsTheListenerIdentifier(): void
+    {
+        $this->listenerProvider->addListener(event: 'Event\\Name', service: 'service.name1');
+        $this->listenerProvider->addListener(event: 'Event\\Name', service: 'service.name2', identifier: 'listenerIdentifier2');
+
+        self::assertEquals([
+            'Event\\Name' => [
+                'service.name1' => [ 'service' => 'service.name1', 'method' => null ],
+                'listenerIdentifier2' => [ 'service' => 'service.name2', 'method' => null ],
             ],
         ], $this->listenerProvider->getAllListenerDefinitions());
     }