diff --git a/core/modules/action/src/ActionFormBase.php b/core/modules/action/src/ActionFormBase.php
index 46b70ede45..db878a9453 100644
--- a/core/modules/action/src/ActionFormBase.php
+++ b/core/modules/action/src/ActionFormBase.php
@@ -132,7 +132,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
    */
   public function save(array $form, FormStateInterface $form_state) {
     $this->entity->save();
-    drupal_set_message($this->t('The action has been successfully saved.'));
+    $this->messenger()->addStatus($this->t('The action has been successfully saved.'));
 
     $form_state->setRedirect('entity.action.collection');
   }
diff --git a/core/modules/action/src/Plugin/Action/MessageAction.php b/core/modules/action/src/Plugin/Action/MessageAction.php
index c85d249b08..9309fc926a 100644
--- a/core/modules/action/src/Plugin/Action/MessageAction.php
+++ b/core/modules/action/src/Plugin/Action/MessageAction.php
@@ -5,6 +5,7 @@
 use Drupal\Core\Access\AccessResult;
 use Drupal\Core\Action\ConfigurableActionBase;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
 use Drupal\Core\Render\RendererInterface;
 use Drupal\Core\Session\AccountInterface;
@@ -36,6 +37,13 @@ class MessageAction extends ConfigurableActionBase implements ContainerFactoryPl
    */
   protected $renderer;
 
+  /**
+   * The messenger.
+   *
+   * @var \Drupal\Core\Messenger\MessengerInterface
+   */
+  protected $messenger;
+
   /**
    * Constructs a MessageAction object.
    *
@@ -49,19 +57,22 @@ class MessageAction extends ConfigurableActionBase implements ContainerFactoryPl
    *   The token service.
    * @param \Drupal\Core\Render\RendererInterface $renderer
    *   The renderer.
+   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
+   *   The messenger.
    */
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, RendererInterface $renderer) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, Token $token, RendererInterface $renderer, MessengerInterface $messenger) {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
 
     $this->token = $token;
     $this->renderer = $renderer;
+    $this->messenger = $messenger;
   }
 
   /**
    * {@inheritdoc}
    */
   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
-    return new static($configuration, $plugin_id, $plugin_definition, $container->get('token'), $container->get('renderer'));
+    return new static($configuration, $plugin_id, $plugin_definition, $container->get('token'), $container->get('renderer'), $container->get('messenger'));
   }
 
   /**
@@ -77,7 +88,7 @@ public function execute($entity = NULL) {
     ];
 
     // @todo Fix in https://www.drupal.org/node/2577827
-    drupal_set_message($this->renderer->renderPlain($build));
+    $this->messenger->addStatus($this->renderer->renderPlain($build));
   }
 
   /**
diff --git a/core/modules/aggregator/src/FeedForm.php b/core/modules/aggregator/src/FeedForm.php
index aed2cd19c3..7fc254780b 100644
--- a/core/modules/aggregator/src/FeedForm.php
+++ b/core/modules/aggregator/src/FeedForm.php
@@ -22,12 +22,12 @@ public function save(array $form, FormStateInterface $form_state) {
     $label = $feed->label();
     $view_link = $feed->link($label, 'canonical');
     if ($status == SAVED_UPDATED) {
-      drupal_set_message($this->t('The feed %feed has been updated.', ['%feed' => $view_link]));
+      $this->messenger()->addStatus($this->t('The feed %feed has been updated.', ['%feed' => $view_link]));
       $form_state->setRedirectUrl($feed->urlInfo('canonical'));
     }
     else {
       $this->logger('aggregator')->notice('Feed %feed added.', ['%feed' => $feed->label(), 'link' => $this->l($this->t('View'), new Url('aggregator.admin_overview'))]);
-      drupal_set_message($this->t('The feed %feed has been added.', ['%feed' => $view_link]));
+      $this->messenger()->addStatus($this->t('The feed %feed has been added.', ['%feed' => $view_link]));
     }
   }
 
diff --git a/core/modules/aggregator/src/Form/OpmlFeedAdd.php b/core/modules/aggregator/src/Form/OpmlFeedAdd.php
index 60a1899362..7958f5f7ba 100644
--- a/core/modules/aggregator/src/Form/OpmlFeedAdd.php
+++ b/core/modules/aggregator/src/Form/OpmlFeedAdd.php
@@ -123,14 +123,14 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       }
       catch (RequestException $e) {
         $this->logger('aggregator')->warning('Failed to download OPML file due to "%error".', ['%error' => $e->getMessage()]);
-        drupal_set_message($this->t('Failed to download OPML file due to "%error".', ['%error' => $e->getMessage()]));
+        $this->messenger()->addStatus($this->t('Failed to download OPML file due to "%error".', ['%error' => $e->getMessage()]));
         return;
       }
     }
 
     $feeds = $this->parseOpml($data);
     if (empty($feeds)) {
-      drupal_set_message($this->t('No new feed has been added.'));
+      $this->messenger()->addStatus($this->t('No new feed has been added.'));
       return;
     }
 
@@ -138,7 +138,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     foreach ($feeds as $feed) {
       // Ensure URL is valid.
       if (!UrlHelper::isValid($feed['url'], TRUE)) {
-        drupal_set_message($this->t('The URL %url is invalid.', ['%url' => $feed['url']]), 'warning');
+        $this->messenger()->addWarning($this->t('The URL %url is invalid.', ['%url' => $feed['url']]));
         continue;
       }
 
@@ -153,11 +153,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       $result = $this->feedStorage->loadMultiple($ids);
       foreach ($result as $old) {
         if (strcasecmp($old->label(), $feed['title']) == 0) {
-          drupal_set_message($this->t('A feed named %title already exists.', ['%title' => $old->label()]), 'warning');
+          $this->messenger()->addWarning($this->t('A feed named %title already exists.', ['%title' => $old->label()]));
           continue 2;
         }
         if (strcasecmp($old->getUrl(), $feed['url']) == 0) {
-          drupal_set_message($this->t('A feed with the URL %url already exists.', ['%url' => $old->getUrl()]), 'warning');
+          $this->messenger()->addWarning($this->t('A feed with the URL %url already exists.', ['%url' => $old->getUrl()]));
           continue 2;
         }
       }
diff --git a/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php b/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php
index 6c6793a59d..3df80a3258 100644
--- a/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php
+++ b/core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php
@@ -6,6 +6,7 @@
 use Drupal\aggregator\FeedInterface;
 use Drupal\Component\Datetime\DateTimePlus;
 use Drupal\Core\Http\ClientFactory;
+use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
 use GuzzleHttp\Exception\RequestException;
 use GuzzleHttp\Psr7\Request;
@@ -42,6 +43,13 @@ class DefaultFetcher implements FetcherInterface, ContainerFactoryPluginInterfac
    */
   protected $logger;
 
+  /**
+   * The messenger.
+   *
+   * @var \Drupal\Core\Messenger\MessengerInterface
+   */
+  protected $messenger;
+
   /**
    * Constructs a DefaultFetcher object.
    *
@@ -49,10 +57,13 @@ class DefaultFetcher implements FetcherInterface, ContainerFactoryPluginInterfac
    *   A Guzzle client object.
    * @param \Psr\Log\LoggerInterface $logger
    *   A logger instance.
+   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
+   *   The messenger.
    */
-  public function __construct(ClientFactory $http_client_factory, LoggerInterface $logger) {
+  public function __construct(ClientFactory $http_client_factory, LoggerInterface $logger, MessengerInterface $messenger) {
     $this->httpClientFactory = $http_client_factory;
     $this->logger = $logger;
+    $this->messenger = $messenger;
   }
 
   /**
@@ -61,7 +72,8 @@ public function __construct(ClientFactory $http_client_factory, LoggerInterface
   public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
     return new static(
       $container->get('http_client_factory'),
-      $container->get('logger.factory')->get('aggregator')
+      $container->get('logger.factory')->get('aggregator'),
+      $container->get('messenger')
     );
   }
 
@@ -115,7 +127,7 @@ public function fetch(FeedInterface $feed) {
     }
     catch (RequestException $e) {
       $this->logger->warning('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()]);
-      drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()]), 'warning');
+      $this->messenger->addWarning(t('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()]));
       return FALSE;
     }
   }
diff --git a/core/modules/aggregator/src/Plugin/aggregator/parser/DefaultParser.php b/core/modules/aggregator/src/Plugin/aggregator/parser/DefaultParser.php
index 03fa55f01c..2694042104 100644
--- a/core/modules/aggregator/src/Plugin/aggregator/parser/DefaultParser.php
+++ b/core/modules/aggregator/src/Plugin/aggregator/parser/DefaultParser.php
@@ -4,6 +4,7 @@
 
 use Drupal\aggregator\Plugin\ParserInterface;
 use Drupal\aggregator\FeedInterface;
+use Drupal\Core\Messenger\MessengerTrait;
 use Zend\Feed\Reader\Reader;
 use Zend\Feed\Reader\Exception\ExceptionInterface;
 
@@ -20,6 +21,8 @@
  */
 class DefaultParser implements ParserInterface {
 
+  use MessengerTrait;
+
   /**
    * {@inheritdoc}
    */
@@ -31,7 +34,7 @@ public function parse(FeedInterface $feed) {
     }
     catch (ExceptionInterface $e) {
       watchdog_exception('aggregator', $e);
-      drupal_set_message(t('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()]), 'error');
+      $this->messenger()->addError(t('The feed from %site seems to be broken because of error "%error".', ['%site' => $feed->label(), '%error' => $e->getMessage()]));
 
       return FALSE;
     }
diff --git a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php
index 4e8200b87b..48405458e1 100644
--- a/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php
+++ b/core/modules/aggregator/src/Plugin/aggregator/processor/DefaultProcessor.php
@@ -3,10 +3,10 @@
 namespace Drupal\aggregator\Plugin\aggregator\processor;
 
 use Drupal\aggregator\Entity\Item;
+use Drupal\aggregator\FeedInterface;
 use Drupal\aggregator\ItemStorageInterface;
 use Drupal\aggregator\Plugin\AggregatorPluginSettingsBase;
 use Drupal\aggregator\Plugin\ProcessorInterface;
-use Drupal\aggregator\FeedInterface;
 use Drupal\Component\Utility\Unicode;
 use Drupal\Core\Config\ConfigFactoryInterface;
 use Drupal\Core\Datetime\DateFormatterInterface;
@@ -28,6 +28,7 @@
  * )
  */
 class DefaultProcessor extends AggregatorPluginSettingsBase implements ProcessorInterface, ContainerFactoryPluginInterface {
+
   use ConfigFormBaseTrait;
   use UrlGeneratorTrait;
 
@@ -231,7 +232,7 @@ public function delete(FeedInterface $feed) {
       $this->itemStorage->delete($items);
     }
     // @todo This should be moved out to caller with a different message maybe.
-    drupal_set_message(t('The news items from %site have been deleted.', ['%site' => $feed->label()]));
+    $this->messenger()->addStatus(t('The news items from %site have been deleted.', ['%site' => $feed->label()]));
   }
 
   /**
diff --git a/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php b/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php
index 56c0339bd6..ac2d5795c7 100644
--- a/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php
+++ b/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php
@@ -4,6 +4,7 @@
 
 use Drupal\aggregator\Form\SettingsForm;
 use Drupal\Core\Form\FormState;
+use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\Tests\UnitTestCase;
 
 /**
@@ -55,6 +56,10 @@ protected function setUp() {
         ->will($this->returnValue(['aggregator_test' => ['title' => '', 'description' => '']]));
     }
 
+    /** @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit_Framework_MockObject_MockBuilder $messenger */
+    $messenger = $this->createMock(MessengerInterface::class);
+    $messenger->expects($this->any())->method('addMessage');
+
     $this->settingsForm = new SettingsForm(
       $this->configFactory,
       $this->managers['fetcher'],
@@ -62,6 +67,7 @@ protected function setUp() {
       $this->managers['processor'],
       $this->getStringTranslationStub()
     );
+    $this->settingsForm->setMessenger($messenger);
   }
 
   /**
@@ -104,11 +110,3 @@ public function testSettingsForm() {
   }
 
 }
-
-// @todo Delete after https://www.drupal.org/node/2278383 is in.
-namespace Drupal\Core\Form;
-
-if (!function_exists('drupal_set_message')) {
-  function drupal_set_message() {
-  }
-}
diff --git a/core/modules/ban/src/Form/BanAdmin.php b/core/modules/ban/src/Form/BanAdmin.php
index 5d8e7957f8..d71be8d402 100644
--- a/core/modules/ban/src/Form/BanAdmin.php
+++ b/core/modules/ban/src/Form/BanAdmin.php
@@ -120,7 +120,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $ip = trim($form_state->getValue('ip'));
     $this->ipManager->banIp($ip);
-    drupal_set_message($this->t('The IP address %ip has been banned.', ['%ip' => $ip]));
+    $this->messenger()->addStatus($this->t('The IP address %ip has been banned.', ['%ip' => $ip]));
     $form_state->setRedirect('ban.admin_page');
   }
 
diff --git a/core/modules/ban/src/Form/BanDelete.php b/core/modules/ban/src/Form/BanDelete.php
index 2d5731f139..9a3ddd48cf 100644
--- a/core/modules/ban/src/Form/BanDelete.php
+++ b/core/modules/ban/src/Form/BanDelete.php
@@ -96,7 +96,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $ban_id =
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $this->ipManager->unbanIp($this->banIp);
     $this->logger('user')->notice('Deleted %ip', ['%ip' => $this->banIp]);
-    drupal_set_message($this->t('The IP address %ip was deleted.', ['%ip' => $this->banIp]));
+    $this->messenger()->addStatus($this->t('The IP address %ip was deleted.', ['%ip' => $this->banIp]));
     $form_state->setRedirectUrl($this->getCancelUrl());
   }
 
diff --git a/core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php b/core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php
index a708ecc882..2405aff5d1 100644
--- a/core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php
+++ b/core/modules/big_pipe/tests/modules/big_pipe_test/src/BigPipeTestController.php
@@ -24,7 +24,7 @@ public function test() {
     if ($has_session) {
       // Only set a message if a session already exists, otherwise we always
       // trigger a session, which means we can't test no-session requests.
-      drupal_set_message('Hello from BigPipe!');
+      \Drupal::messenger()->addStatus('Hello from BigPipe!');
     }
     $build['html'] = $cases['html']->renderArray;
 
diff --git a/core/modules/block/block.module b/core/modules/block/block.module
index ee6a4a11ea..28fd7b30c6 100644
--- a/core/modules/block/block.module
+++ b/core/modules/block/block.module
@@ -145,7 +145,11 @@ function block_rebuild() {
         // Disable blocks in invalid regions.
         if (!isset($regions[$block->getRegion()])) {
           if ($block->status()) {
-            drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block_id, '%region' => $block->getRegion()]), 'warning');
+            \Drupal::messenger()
+              ->addWarning(t('The block %info was assigned to the invalid region %region and has been disabled.', [
+                '%info' => $block_id,
+                '%region' => $block->getRegion(),
+              ]));
           }
           $block
             ->setRegion(system_default_region($theme))
diff --git a/core/modules/block/src/BlockForm.php b/core/modules/block/src/BlockForm.php
index 04160432de..ada7f6e03e 100644
--- a/core/modules/block/src/BlockForm.php
+++ b/core/modules/block/src/BlockForm.php
@@ -359,7 +359,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     // Save the settings of the plugin.
     $entity->save();
 
-    drupal_set_message($this->t('The block configuration has been saved.'));
+    $this->messenger()->addStatus($this->t('The block configuration has been saved.'));
     $form_state->setRedirect(
       'block.admin_display_theme',
       [
diff --git a/core/modules/block/src/BlockListBuilder.php b/core/modules/block/src/BlockListBuilder.php
index 37b2e8bfc3..6244f09de2 100644
--- a/core/modules/block/src/BlockListBuilder.php
+++ b/core/modules/block/src/BlockListBuilder.php
@@ -367,7 +367,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       $entity->setRegion($entity_values['region']);
       $entity->save();
     }
-    drupal_set_message(t('The block settings have been updated.'));
+    $this->messenger()->addStatus(t('The block settings have been updated.'));
 
     // Remove any previously set block placement.
     $this->request->query->remove('block-placement');
diff --git a/core/modules/block/src/Controller/BlockController.php b/core/modules/block/src/Controller/BlockController.php
index 7398ff98e1..543ce59038 100644
--- a/core/modules/block/src/Controller/BlockController.php
+++ b/core/modules/block/src/Controller/BlockController.php
@@ -53,7 +53,7 @@ public static function create(ContainerInterface $container) {
    */
   public function performOperation(BlockInterface $block, $op) {
     $block->$op()->save();
-    drupal_set_message($this->t('The block settings have been updated.'));
+    $this->messenger()->addStatus($this->t('The block settings have been updated.'));
     return $this->redirect('block.admin_display');
   }
 
diff --git a/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
index e7aac65500..775f1c6a62 100644
--- a/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
+++ b/core/modules/block/tests/modules/block_test/src/Controller/TestMultipleFormController.php
@@ -26,7 +26,7 @@ public function testMultipleForms() {
       $action_values = $matches[2];
 
       foreach ($action_values as $action_value) {
-        drupal_set_message('Form action: ' . $action_value);
+        $this->messenger()->addStatus('Form action: ' . $action_value);
       }
       return $elements;
     };
diff --git a/core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php b/core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php
index 3ad55edff2..a86db68dfc 100644
--- a/core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php
+++ b/core/modules/block/tests/modules/block_test/src/Form/FavoriteAnimalTestForm.php
@@ -40,7 +40,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
    * {@inheritdoc}
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
-    drupal_set_message($this->t('Your favorite animal is: @favorite_animal', ['@favorite_animal' => $form['favorite_animal']['#value']]));
+    $this->messenger()->addStatus($this->t('Your favorite animal is: @favorite_animal', ['@favorite_animal' => $form['favorite_animal']['#value']]));
   }
 
 }
diff --git a/core/modules/block/tests/modules/block_test/src/Form/TestForm.php b/core/modules/block/tests/modules/block_test/src/Form/TestForm.php
index 7fa645df5f..7619d842d1 100644
--- a/core/modules/block/tests/modules/block_test/src/Form/TestForm.php
+++ b/core/modules/block/tests/modules/block_test/src/Form/TestForm.php
@@ -49,7 +49,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
    * {@inheritdoc}
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
-    drupal_set_message($this->t('Your email address is @email', ['@email' => $form['email']['#value']]));
+    $this->messenger()->addStatus($this->t('Your email address is @email', ['@email' => $form['email']['#value']]));
   }
 
 }
diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
index 7db350da81..51f60b473a 100644
--- a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
+++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestContextAwareBlock.php
@@ -37,7 +37,7 @@ public function build() {
    */
   protected function blockAccess(AccountInterface $account) {
     if ($this->getContextValue('user') instanceof UserInterface) {
-      drupal_set_message('User context found.');
+      $this->messenger()->addStatus('User context found.');
     }
 
     return parent::blockAccess($account);
diff --git a/core/modules/block/tests/src/Kernel/BlockRebuildTest.php b/core/modules/block/tests/src/Kernel/BlockRebuildTest.php
index 33de12ce87..2443c21052 100644
--- a/core/modules/block/tests/src/Kernel/BlockRebuildTest.php
+++ b/core/modules/block/tests/src/Kernel/BlockRebuildTest.php
@@ -47,7 +47,8 @@ public static function setUpBeforeClass() {
    */
   public function testRebuildNoBlocks() {
     block_rebuild();
-    $messages = drupal_get_messages();
+    $messages = \Drupal::messenger()->all();
+    \Drupal::messenger()->deleteAll();
     $this->assertEquals([], $messages);
   }
 
@@ -58,7 +59,8 @@ public function testRebuildNoInvalidBlocks() {
     $this->placeBlock('system_powered_by_block', ['region' => 'content']);
 
     block_rebuild();
-    $messages = drupal_get_messages();
+    $messages = \Drupal::messenger()->all();
+    \Drupal::messenger()->deleteAll();
     $this->assertEquals([], $messages);
   }
 
@@ -89,7 +91,8 @@ public function testRebuildInvalidBlocks() {
     $block1 = Block::load($block1->id());
     $block2 = Block::load($block2->id());
 
-    $messages = drupal_get_messages();
+    $messages = \Drupal::messenger()->all();
+    \Drupal::messenger()->deleteAll();
     $expected = ['warning' => [new TranslatableMarkup('The block %info was assigned to the invalid region %region and has been disabled.', ['%info' => $block1->id(), '%region' => 'INVALID'])]];
     $this->assertEquals($expected, $messages);
 
diff --git a/core/modules/block_content/src/BlockContentForm.php b/core/modules/block_content/src/BlockContentForm.php
index 225dc91b46..9df2a87d73 100644
--- a/core/modules/block_content/src/BlockContentForm.php
+++ b/core/modules/block_content/src/BlockContentForm.php
@@ -54,11 +54,11 @@ public function save(array $form, FormStateInterface $form_state) {
 
     if ($insert) {
       $logger->notice('@type: added %info.', $context);
-      drupal_set_message($this->t('@type %info has been created.', $t_args));
+      $this->messenger()->addStatus($this->t('@type %info has been created.', $t_args));
     }
     else {
       $logger->notice('@type: updated %info.', $context);
-      drupal_set_message($this->t('@type %info has been updated.', $t_args));
+      $this->messenger()->addStatus($this->t('@type %info has been updated.', $t_args));
     }
 
     if ($block->id()) {
@@ -83,7 +83,7 @@ public function save(array $form, FormStateInterface $form_state) {
     else {
       // In the unlikely case something went wrong on save, the block will be
       // rebuilt and block form redisplayed.
-      drupal_set_message($this->t('The block could not be saved.'), 'error');
+      $this->messenger()->addError($this->t('The block could not be saved.'));
       $form_state->setRebuild();
     }
   }
diff --git a/core/modules/block_content/src/BlockContentTypeForm.php b/core/modules/block_content/src/BlockContentTypeForm.php
index 00098d3cf3..711cda678b 100644
--- a/core/modules/block_content/src/BlockContentTypeForm.php
+++ b/core/modules/block_content/src/BlockContentTypeForm.php
@@ -100,12 +100,12 @@ public function save(array $form, FormStateInterface $form_state) {
     $edit_link = $this->entity->link($this->t('Edit'));
     $logger = $this->logger('block_content');
     if ($status == SAVED_UPDATED) {
-      drupal_set_message(t('Custom block type %label has been updated.', ['%label' => $block_type->label()]));
+      $this->messenger()->addStatus(t('Custom block type %label has been updated.', ['%label' => $block_type->label()]));
       $logger->notice('Custom block type %label has been updated.', ['%label' => $block_type->label(), 'link' => $edit_link]);
     }
     else {
       block_content_add_body_field($block_type->id());
-      drupal_set_message(t('Custom block type %label has been added.', ['%label' => $block_type->label()]));
+      $this->messenger()->addStatus(t('Custom block type %label has been added.', ['%label' => $block_type->label()]));
       $logger->notice('Custom block type %label has been added.', ['%label' => $block_type->label(), 'link' => $edit_link]);
     }
 
diff --git a/core/modules/book/src/Controller/BookController.php b/core/modules/book/src/Controller/BookController.php
index b92c3e3fcf..fa34d92711 100644
--- a/core/modules/book/src/Controller/BookController.php
+++ b/core/modules/book/src/Controller/BookController.php
@@ -154,7 +154,7 @@ public function bookExport($type, NodeInterface $node) {
 
     // @todo Convert the custom export functionality to serializer.
     if (!method_exists($this->bookExport, $method)) {
-      drupal_set_message(t('Unknown export format.'));
+      $this->messenger()->addStatus(t('Unknown export format.'));
       throw new NotFoundHttpException();
     }
 
diff --git a/core/modules/book/src/Form/BookAdminEditForm.php b/core/modules/book/src/Form/BookAdminEditForm.php
index 66e717eaba..e052b7cff1 100644
--- a/core/modules/book/src/Form/BookAdminEditForm.php
+++ b/core/modules/book/src/Form/BookAdminEditForm.php
@@ -127,7 +127,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       }
     }
 
-    drupal_set_message($this->t('Updated book %title.', ['%title' => $form['#node']->label()]));
+    $this->messenger()->addStatus($this->t('Updated book %title.', ['%title' => $form['#node']->label()]));
   }
 
   /**
diff --git a/core/modules/book/src/Form/BookOutlineForm.php b/core/modules/book/src/Form/BookOutlineForm.php
index f7ea043ed2..1ce771e0de 100644
--- a/core/modules/book/src/Form/BookOutlineForm.php
+++ b/core/modules/book/src/Form/BookOutlineForm.php
@@ -113,7 +113,7 @@ public function save(array $form, FormStateInterface $form_state) {
     );
     $book_link = $form_state->getValue('book');
     if (!$book_link['bid']) {
-      drupal_set_message($this->t('No changes were made'));
+      $this->messenger()->addStatus($this->t('No changes were made'));
       return;
     }
 
@@ -121,15 +121,15 @@ public function save(array $form, FormStateInterface $form_state) {
     if ($this->bookManager->updateOutline($this->entity)) {
       if (isset($this->entity->book['parent_mismatch']) && $this->entity->book['parent_mismatch']) {
         // This will usually only happen when JS is disabled.
-        drupal_set_message($this->t('The post has been added to the selected book. You may now position it relative to other pages.'));
+        $this->messenger()->addStatus($this->t('The post has been added to the selected book. You may now position it relative to other pages.'));
         $form_state->setRedirectUrl($this->entity->urlInfo('book-outline-form'));
       }
       else {
-        drupal_set_message($this->t('The book outline has been updated.'));
+        $this->messenger()->addStatus($this->t('The book outline has been updated.'));
       }
     }
     else {
-      drupal_set_message($this->t('There was an error adding the post to the book.'), 'error');
+      $this->messenger()->addError($this->t('There was an error adding the post to the book.'));
     }
   }
 
diff --git a/core/modules/book/src/Form/BookRemoveForm.php b/core/modules/book/src/Form/BookRemoveForm.php
index f61aa775a5..2d5a91982f 100644
--- a/core/modules/book/src/Form/BookRemoveForm.php
+++ b/core/modules/book/src/Form/BookRemoveForm.php
@@ -103,7 +103,7 @@ public function getCancelUrl() {
   public function submitForm(array &$form, FormStateInterface $form_state) {
     if ($this->bookManager->checkNodeIsRemovable($this->node)) {
       $this->bookManager->deleteFromBook($this->node->id());
-      drupal_set_message($this->t('The post has been removed from the book.'));
+      $this->messenger()->addStatus($this->t('The post has been removed from the book.'));
     }
     $form_state->setRedirectUrl($this->getCancelUrl());
   }
diff --git a/core/modules/book/tests/modules/book_test/book_test.module b/core/modules/book/tests/modules/book_test/book_test.module
index 939e75628b..91da82c289 100644
--- a/core/modules/book/tests/modules/book_test/book_test.module
+++ b/core/modules/book/tests/modules/book_test/book_test.module
@@ -17,6 +17,6 @@
 function book_test_page_attachments(array &$page) {
   $page['#cache']['tags'][] = 'book_test.debug_book_navigation_cache_context';
   if (\Drupal::state()->get('book_test.debug_book_navigation_cache_context', FALSE)) {
-    drupal_set_message(\Drupal::service('cache_contexts_manager')->convertTokensToKeys(['route.book_navigation'])->getKeys()[0]);
+    \Drupal::messenger()->addStatus(\Drupal::service('cache_contexts_manager')->convertTokensToKeys(['route.book_navigation'])->getKeys()[0]);
   }
 }
diff --git a/core/modules/color/color.module b/core/modules/color/color.module
index f4ee9fd6e7..c16db11309 100644
--- a/core/modules/color/color.module
+++ b/core/modules/color/color.module
@@ -414,7 +414,7 @@ function color_scheme_form_submit($form, FormStateInterface $form_state) {
     $memory_limit = ini_get('memory_limit');
     $size = Bytes::toInt($memory_limit);
     if (!Environment::checkMemoryLimit($usage + $required, $memory_limit)) {
-      drupal_set_message(t('There is not enough memory available to PHP to change this theme\'s color scheme. You need at least %size more. Check the <a href="http://php.net/manual/ini.core.php#ini.sect.resource-limits">PHP documentation</a> for more information.', ['%size' => format_size($usage + $required - $size)]), 'error');
+      \Drupal::messenger()->addError(t('There is not enough memory available to PHP to change this theme\'s color scheme. You need at least %size more. Check the <a href="http://php.net/manual/ini.core.php#ini.sect.resource-limits">PHP documentation</a> for more information.', ['%size' => format_size($usage + $required - $size)]));
       return;
     }
   }
diff --git a/core/modules/comment/src/CommentForm.php b/core/modules/comment/src/CommentForm.php
index 98e9ddef96..00647ad042 100644
--- a/core/modules/comment/src/CommentForm.php
+++ b/core/modules/comment/src/CommentForm.php
@@ -375,11 +375,11 @@ public function save(array $form, FormStateInterface $form_state) {
       // Explain the approval queue if necessary.
       if (!$comment->isPublished()) {
         if (!$this->currentUser->hasPermission('administer comments')) {
-          drupal_set_message($this->t('Your comment has been queued for review by site administrators and will be published after approval.'));
+          $this->messenger()->addStatus($this->t('Your comment has been queued for review by site administrators and will be published after approval.'));
         }
       }
       else {
-        drupal_set_message($this->t('Your comment has been posted.'));
+        $this->messenger()->addStatus($this->t('Your comment has been posted.'));
       }
       $query = [];
       // Find the current display page for this comment.
@@ -394,7 +394,7 @@ public function save(array $form, FormStateInterface $form_state) {
     }
     else {
       $logger->warning('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', ['%subject' => $comment->getSubject()]);
-      drupal_set_message($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', ['%subject' => $comment->getSubject()]), 'error');
+      $this->messenger()->addError($this->t('Comment: unauthorized comment submitted or comment submitted to a closed post %subject.', ['%subject' => $comment->getSubject()]));
       // Redirect the user to the entity they are commenting on.
     }
     $form_state->setRedirectUrl($uri);
diff --git a/core/modules/comment/src/CommentTypeForm.php b/core/modules/comment/src/CommentTypeForm.php
index 0ac5b446bd..401ce8f25f 100644
--- a/core/modules/comment/src/CommentTypeForm.php
+++ b/core/modules/comment/src/CommentTypeForm.php
@@ -160,12 +160,12 @@ public function save(array $form, FormStateInterface $form_state) {
 
     $edit_link = $this->entity->link($this->t('Edit'));
     if ($status == SAVED_UPDATED) {
-      drupal_set_message(t('Comment type %label has been updated.', ['%label' => $comment_type->label()]));
+      $this->messenger()->addStatus(t('Comment type %label has been updated.', ['%label' => $comment_type->label()]));
       $this->logger->notice('Comment type %label has been updated.', ['%label' => $comment_type->label(), 'link' => $edit_link]);
     }
     else {
       $this->commentManager->addBodyField($comment_type->id());
-      drupal_set_message(t('Comment type %label has been added.', ['%label' => $comment_type->label()]));
+      $this->messenger()->addStatus(t('Comment type %label has been added.', ['%label' => $comment_type->label()]));
       $this->logger->notice('Comment type %label has been added.', ['%label' => $comment_type->label(), 'link' => $edit_link]);
     }
 
diff --git a/core/modules/comment/src/Controller/CommentController.php b/core/modules/comment/src/Controller/CommentController.php
index a01106d77f..9ab3a07edd 100644
--- a/core/modules/comment/src/Controller/CommentController.php
+++ b/core/modules/comment/src/Controller/CommentController.php
@@ -85,7 +85,7 @@ public function commentApprove(CommentInterface $comment) {
     $comment->setPublished(TRUE);
     $comment->save();
 
-    drupal_set_message($this->t('Comment approved.'));
+    $this->messenger()->addStatus($this->t('Comment approved.'));
     $permalink_uri = $comment->permalink();
     $permalink_uri->setAbsolute();
     return new RedirectResponse($permalink_uri->toString());
diff --git a/core/modules/comment/src/Form/CommentAdminOverview.php b/core/modules/comment/src/Form/CommentAdminOverview.php
index 8a93ecd856..3b97d0d1c4 100644
--- a/core/modules/comment/src/Form/CommentAdminOverview.php
+++ b/core/modules/comment/src/Form/CommentAdminOverview.php
@@ -279,7 +279,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
         }
         $comment->save();
       }
-      drupal_set_message($this->t('The update has been performed.'));
+      $this->messenger()->addStatus($this->t('The update has been performed.'));
       $form_state->setRedirect('comment.admin');
     }
     else {
diff --git a/core/modules/config/src/Form/ConfigImportForm.php b/core/modules/config/src/Form/ConfigImportForm.php
index 6b7b557c15..28852f24ea 100644
--- a/core/modules/config/src/Form/ConfigImportForm.php
+++ b/core/modules/config/src/Form/ConfigImportForm.php
@@ -55,7 +55,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
     $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY);
     $directory_is_writable = is_writable($directory);
     if (!$directory_is_writable) {
-      drupal_set_message($this->t('The directory %directory is not writable.', ['%directory' => $directory]), 'error');
+      $this->messenger()->addError($this->t('The directory %directory is not writable.', ['%directory' => $directory]));
     }
     $form['import_tarball'] = [
       '#type' => 'file',
@@ -100,11 +100,11 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
           $files[] = $file['filename'];
         }
         $archiver->extractList($files, config_get_config_directory(CONFIG_SYNC_DIRECTORY));
-        drupal_set_message($this->t('Your configuration files were successfully uploaded and are ready for import.'));
+        $this->messenger()->addStatus($this->t('Your configuration files were successfully uploaded and are ready for import.'));
         $form_state->setRedirect('config.sync');
       }
       catch (\Exception $e) {
-        drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', ['@message' => $e->getMessage()]), 'error');
+        $this->messenger()->addError($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', ['@message' => $e->getMessage()]));
       }
       drupal_unlink($path);
     }
diff --git a/core/modules/config/src/Form/ConfigSingleImportForm.php b/core/modules/config/src/Form/ConfigSingleImportForm.php
index 9f9a8d9281..560f124c84 100644
--- a/core/modules/config/src/Form/ConfigSingleImportForm.php
+++ b/core/modules/config/src/Form/ConfigSingleImportForm.php
@@ -395,7 +395,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     /** @var \Drupal\Core\Config\ConfigImporter $config_importer */
     $config_importer = $form_state->get('config_importer');
     if ($config_importer->alreadyImporting()) {
-      drupal_set_message($this->t('Another request may be importing configuration already.'), 'error');
+      $this->messenger()->addError($this->t('Another request may be importing configuration already.'));
     }
     else {
       try {
@@ -416,9 +416,9 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       }
       catch (ConfigImporterException $e) {
         // There are validation errors.
-        drupal_set_message($this->t('The configuration import failed for the following reasons:'), 'error');
+        $this->messenger()->addError($this->t('The configuration import failed for the following reasons:'));
         foreach ($config_importer->getErrors() as $message) {
-          drupal_set_message($message, 'error');
+          $this->messenger()->addError($message);
         }
       }
     }
diff --git a/core/modules/config/src/Form/ConfigSync.php b/core/modules/config/src/Form/ConfigSync.php
index 281309922a..e8a3ea2d1f 100644
--- a/core/modules/config/src/Form/ConfigSync.php
+++ b/core/modules/config/src/Form/ConfigSync.php
@@ -191,7 +191,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
       return $form;
     }
     elseif (!$storage_comparer->validateSiteUuid()) {
-      drupal_set_message($this->t('The staged configuration cannot be imported, because it originates from a different site than this site. You can only synchronize configuration between cloned instances of this site.'), 'error');
+      $this->messenger()->addError($this->t('The staged configuration cannot be imported, because it originates from a different site than this site. You can only synchronize configuration between cloned instances of this site.'));
       $form['actions']['#access'] = FALSE;
       return $form;
     }
@@ -221,7 +221,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
             '#items' => $change_list,
           ]
         ];
-        drupal_set_message($this->renderer->renderPlain($message), 'warning');
+        $this->messenger()->addWarning($this->renderer->renderPlain($message));
       }
     }
 
@@ -330,7 +330,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       $this->getStringTranslation()
     );
     if ($config_importer->alreadyImporting()) {
-      drupal_set_message($this->t('Another request may be synchronizing configuration already.'));
+      $this->messenger()->addStatus($this->t('Another request may be synchronizing configuration already.'));
     }
     else {
       try {
@@ -352,9 +352,9 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       }
       catch (ConfigImporterException $e) {
         // There are validation errors.
-        drupal_set_message($this->t('The configuration cannot be imported because it failed validation for the following reasons:'), 'error');
+        $this->messenger()->addError($this->t('The configuration cannot be imported because it failed validation for the following reasons:'));
         foreach ($config_importer->getErrors() as $message) {
-          drupal_set_message($message, 'error');
+          $this->messenger()->addError($message);
         }
       }
     }
@@ -395,13 +395,13 @@ public static function finishBatch($success, $results, $operations) {
     if ($success) {
       if (!empty($results['errors'])) {
         foreach ($results['errors'] as $error) {
-          drupal_set_message($error, 'error');
+          \Drupal::messenger()->addError($error);
           \Drupal::logger('config_sync')->error($error);
         }
-        drupal_set_message(\Drupal::translation()->translate('The configuration was imported with errors.'), 'warning');
+        \Drupal::messenger()->addWarning(\Drupal::translation()->translate('The configuration was imported with errors.'));
       }
       else {
-        drupal_set_message(\Drupal::translation()->translate('The configuration was imported successfully.'));
+        \Drupal::messenger()->addStatus(\Drupal::translation()->translate('The configuration was imported successfully.'));
       }
     }
     else {
@@ -409,7 +409,7 @@ public static function finishBatch($success, $results, $operations) {
       // $operations contains the operations that remained unprocessed.
       $error_operation = reset($operations);
       $message = \Drupal::translation()->translate('An error occurred while processing %error_operation with arguments: @arguments', ['%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE)]);
-      drupal_set_message($message, 'error');
+      \Drupal::messenger()->addError($message);
     }
   }
 
diff --git a/core/modules/config/tests/config_test/src/ConfigTestForm.php b/core/modules/config/tests/config_test/src/ConfigTestForm.php
index fbc0f9661d..86e021e38c 100644
--- a/core/modules/config/tests/config_test/src/ConfigTestForm.php
+++ b/core/modules/config/tests/config_test/src/ConfigTestForm.php
@@ -138,10 +138,10 @@ public function save(array $form, FormStateInterface $form_state) {
     $status = $entity->save();
 
     if ($status === SAVED_UPDATED) {
-      drupal_set_message(format_string('%label configuration has been updated.', ['%label' => $entity->label()]));
+      $this->messenger()->addStatus(format_string('%label configuration has been updated.', ['%label' => $entity->label()]));
     }
     else {
-      drupal_set_message(format_string('%label configuration has been created.', ['%label' => $entity->label()]));
+      $this->messenger()->addStatus(format_string('%label configuration has been created.', ['%label' => $entity->label()]));
     }
 
     $form_state->setRedirectUrl($this->entity->urlInfo('collection'));
diff --git a/core/modules/config_translation/src/Controller/ConfigTranslationController.php b/core/modules/config_translation/src/Controller/ConfigTranslationController.php
index a8c426ae0e..b4d3356569 100644
--- a/core/modules/config_translation/src/Controller/ConfigTranslationController.php
+++ b/core/modules/config_translation/src/Controller/ConfigTranslationController.php
@@ -139,7 +139,7 @@ public function itemPage(Request $request, RouteMatchInterface $route_match, $pl
 
     $languages = $this->languageManager->getLanguages();
     if (count($languages) == 1) {
-      drupal_set_message($this->t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', [':url' => $this->url('entity.configurable_language.collection')]), 'warning');
+      $this->messenger()->addWarning($this->t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', [':url' => $this->url('entity.configurable_language.collection')]));
     }
 
     try {
@@ -162,7 +162,7 @@ public function itemPage(Request $request, RouteMatchInterface $route_match, $pl
           '#items' => $items,
         ],
       ];
-      drupal_set_message($this->renderer->renderPlain($message), 'warning');
+      $this->messenger()->addWarning($this->renderer->renderPlain($message));
 
       $original_langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
       $operations_access = FALSE;
diff --git a/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php b/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php
index 812b1a11bb..8b3f4a8966 100644
--- a/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php
+++ b/core/modules/config_translation/src/Form/ConfigTranslationAddForm.php
@@ -36,7 +36,7 @@ public function buildForm(array $form, FormStateInterface $form_state, RouteMatc
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     parent::submitForm($form, $form_state);
-    drupal_set_message($this->t('Successfully saved @language translation.', ['@language' => $this->language->getName()]));
+    $this->messenger()->addStatus($this->t('Successfully saved @language translation.', ['@language' => $this->language->getName()]));
   }
 
 }
diff --git a/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php b/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php
index 273b26c9e5..d420ee63dc 100644
--- a/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php
+++ b/core/modules/config_translation/src/Form/ConfigTranslationDeleteForm.php
@@ -142,7 +142,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       $cache_backend->deleteAll();
     }
 
-    drupal_set_message($this->t('@language translation of %label was deleted', ['%label' => $this->mapper->getTitle(), '@language' => $this->language->getName()]));
+    $this->messenger()->addStatus($this->t('@language translation of %label was deleted', ['%label' => $this->mapper->getTitle(), '@language' => $this->language->getName()]));
 
     $form_state->setRedirectUrl($this->getCancelUrl());
   }
diff --git a/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php b/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php
index cdbd9b898c..8754d91650 100644
--- a/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php
+++ b/core/modules/config_translation/src/Form/ConfigTranslationEditForm.php
@@ -36,7 +36,7 @@ public function buildForm(array $form, FormStateInterface $form_state, RouteMatc
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     parent::submitForm($form, $form_state);
-    drupal_set_message($this->t('Successfully updated @language translation.', ['@language' => $this->language->getName()]));
+    $this->messenger()->addStatus($this->t('Successfully updated @language translation.', ['@language' => $this->language->getName()]));
   }
 
 }
diff --git a/core/modules/contact/src/ContactFormEditForm.php b/core/modules/contact/src/ContactFormEditForm.php
index 1df695337b..7e78f7835d 100644
--- a/core/modules/contact/src/ContactFormEditForm.php
+++ b/core/modules/contact/src/ContactFormEditForm.php
@@ -167,11 +167,11 @@ public function save(array $form, FormStateInterface $form_state) {
     $edit_link = $this->entity->link($this->t('Edit'));
     $view_link = $contact_form->link($contact_form->label(), 'canonical');
     if ($status == SAVED_UPDATED) {
-      drupal_set_message($this->t('Contact form %label has been updated.', ['%label' => $view_link]));
+      $this->messenger()->addStatus($this->t('Contact form %label has been updated.', ['%label' => $view_link]));
       $this->logger('contact')->notice('Contact form %label has been updated.', ['%label' => $contact_form->label(), 'link' => $edit_link]);
     }
     else {
-      drupal_set_message($this->t('Contact form %label has been added.', ['%label' => $view_link]));
+      $this->messenger()->addStatus($this->t('Contact form %label has been added.', ['%label' => $view_link]));
       $this->logger('contact')->notice('Contact form %label has been added.', ['%label' => $contact_form->label(), 'link' => $edit_link]);
     }
 
diff --git a/core/modules/contact/src/Controller/ContactController.php b/core/modules/contact/src/Controller/ContactController.php
index 35655342f6..1844280f55 100644
--- a/core/modules/contact/src/Controller/ContactController.php
+++ b/core/modules/contact/src/Controller/ContactController.php
@@ -64,9 +64,9 @@ public function contactSitePage(ContactFormInterface $contact_form = NULL) {
       // If there are no forms, do not display the form.
       if (empty($contact_form)) {
         if ($this->currentUser()->hasPermission('administer contact forms')) {
-          drupal_set_message($this->t('The contact form has not been configured. <a href=":add">Add one or more forms</a> .', [
+          $this->messenger()->addError($this->t('The contact form has not been configured. <a href=":add">Add one or more forms</a> .', [
             ':add' => $this->url('contact.form_add'),
-          ]), 'error');
+          ]));
           return [];
         }
         else {
diff --git a/core/modules/contact/src/MessageForm.php b/core/modules/contact/src/MessageForm.php
index c555f3bcec..3c4030c2ab 100644
--- a/core/modules/contact/src/MessageForm.php
+++ b/core/modules/contact/src/MessageForm.php
@@ -224,7 +224,7 @@ public function save(array $form, FormStateInterface $form_state) {
 
     $this->flood->register('contact', $this->config('contact.settings')->get('flood.interval'));
     if ($submission_message = $contact_form->getMessage()) {
-      drupal_set_message($submission_message);
+      $this->messenger()->addStatus($submission_message);
     }
 
     // To avoid false error messages caused by flood control, redirect away from
diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php
index 5c7cda929b..2e19810c46 100644
--- a/core/modules/content_moderation/src/EntityTypeInfo.php
+++ b/core/modules/content_moderation/src/EntityTypeInfo.php
@@ -12,6 +12,8 @@
 use Drupal\Core\Entity\EntityTypeManagerInterface;
 use Drupal\Core\Field\BaseFieldDefinition;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Messenger\MessengerInterface;
+use Drupal\Core\Messenger\MessengerTrait;
 use Drupal\Core\Session\AccountInterface;
 use Drupal\Core\StringTranslation\StringTranslationTrait;
 use Drupal\Core\StringTranslation\TranslationInterface;
@@ -31,6 +33,7 @@
  */
 class EntityTypeInfo implements ContainerInjectionInterface {
 
+  use MessengerTrait;
   use StringTranslationTrait;
 
   /**
@@ -93,14 +96,19 @@ class EntityTypeInfo implements ContainerInjectionInterface {
    *   Bundle information service.
    * @param \Drupal\Core\Session\AccountInterface $current_user
    *   Current user.
+   * @param \Drupal\content_moderation\StateTransitionValidationInterface $validator
+   *   The state transition validator.
+   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
+   *   The messenger.
    */
-  public function __construct(TranslationInterface $translation, ModerationInformationInterface $moderation_information, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info, AccountInterface $current_user, StateTransitionValidationInterface $validator) {
+  public function __construct(TranslationInterface $translation, ModerationInformationInterface $moderation_information, EntityTypeManagerInterface $entity_type_manager, EntityTypeBundleInfoInterface $bundle_info, AccountInterface $current_user, StateTransitionValidationInterface $validator, MessengerInterface $messenger) {
     $this->stringTranslation = $translation;
     $this->moderationInfo = $moderation_information;
     $this->entityTypeManager = $entity_type_manager;
     $this->bundleInfo = $bundle_info;
     $this->currentUser = $current_user;
     $this->validator = $validator;
+    $this->messenger = $messenger;
   }
 
   /**
@@ -113,11 +121,11 @@ public static function create(ContainerInterface $container) {
       $container->get('entity_type.manager'),
       $container->get('entity_type.bundle.info'),
       $container->get('current_user'),
-      $container->get('content_moderation.state_transition_validation')
+      $container->get('content_moderation.state_transition_validation'),
+      $container->get('messenger')
     );
   }
 
-
   /**
    * Adds Moderation configuration to appropriate entity types.
    *
@@ -318,7 +326,7 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id
           $label = $this->t('Unable to save this @type_label.', $args);
           $message = $this->t('<a href="@latest_revision_edit_url">Publish</a> or <a href="@latest_revision_delete_url">delete</a> the latest revision to allow all workflow transitions.', $args);
           $full_message = $this->t('Unable to save this @type_label. <a href="@latest_revision_edit_url">Publish</a> or <a href="@latest_revision_delete_url">delete</a> the latest revision to allow all workflow transitions.', $args);
-          drupal_set_message($full_message, 'error');
+          $this->messenger()->addStatus($full_message, 'error');
 
           $form['moderation_state']['#access'] = FALSE;
           $form['actions']['#access'] = FALSE;
diff --git a/core/modules/content_moderation/src/Form/EntityModerationForm.php b/core/modules/content_moderation/src/Form/EntityModerationForm.php
index 507ef54485..13731199fd 100644
--- a/core/modules/content_moderation/src/Form/EntityModerationForm.php
+++ b/core/modules/content_moderation/src/Form/EntityModerationForm.php
@@ -150,7 +150,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     }
     $entity->save();
 
-    drupal_set_message($this->t('The moderation state has been updated.'));
+    $this->messenger()->addStatus($this->t('The moderation state has been updated.'));
 
     $new_state = $this->moderationInfo->getWorkflowForEntity($entity)->getTypePlugin()->getState($new_state);
     // The page we're on likely won't be visible if we just set the entity to
diff --git a/core/modules/content_translation/content_translation.install b/core/modules/content_translation/content_translation.install
index 0e47270092..93a9968221 100644
--- a/core/modules/content_translation/content_translation.install
+++ b/core/modules/content_translation/content_translation.install
@@ -23,14 +23,14 @@ function content_translation_install() {
       ':language_url' => Url::fromRoute('entity.configurable_language.collection')->toString()
     ];
     $message = t('This site has only a single language enabled. <a href=":language_url">Add at least one more language</a> in order to translate content.', $t_args);
-    drupal_set_message($message, 'warning');
+    \Drupal::messenger()->addWarning($message);
   }
   // Point the user to the content translation settings.
   $t_args = [
     ':settings_url' => Url::fromRoute('language.content_settings_page')->toString()
   ];
   $message = t('<a href=":settings_url">Enable translation</a> for <em>content types</em>, <em>taxonomy vocabularies</em>, <em>accounts</em>, or any other element you wish to translate.', $t_args);
-  drupal_set_message($message, 'warning');
+  \Drupal::messenger()->addWarning($message);
 }
 
 /**
diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php
index 2ba76e7915..c009b30120 100644
--- a/core/modules/content_translation/src/ContentTranslationHandler.php
+++ b/core/modules/content_translation/src/ContentTranslationHandler.php
@@ -713,7 +713,7 @@ public function entityFormSourceChange($form, FormStateInterface $form_state) {
       'target' => $form_object->getFormLangcode($form_state),
     ]);
     $languages = $this->languageManager->getLanguages();
-    drupal_set_message(t('Source language set to: %language', ['%language' => $languages[$source]->getName()]));
+    $this->messenger()->addStatus(t('Source language set to: %language', ['%language' => $languages[$source]->getName()]));
   }
 
   /**
@@ -725,7 +725,7 @@ public function entityFormDelete($form, FormStateInterface $form_state) {
     $form_object = $form_state->getFormObject()->getEntity();
     $entity = $form_object->getEntity();
     if (count($entity->getTranslationLanguages()) > 1) {
-      drupal_set_message(t('This will delete all the translations of %label.', ['%label' => $entity->label()]), 'warning');
+      $this->messenger()->addWarning(t('This will delete all the translations of %label.', ['%label' => $entity->label()]));
     }
   }
 
diff --git a/core/modules/dblog/src/Form/DblogClearLogConfirmForm.php b/core/modules/dblog/src/Form/DblogClearLogConfirmForm.php
index 46344eba06..e567729b36 100644
--- a/core/modules/dblog/src/Form/DblogClearLogConfirmForm.php
+++ b/core/modules/dblog/src/Form/DblogClearLogConfirmForm.php
@@ -68,7 +68,7 @@ public function getCancelUrl() {
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $_SESSION['dblog_overview_filter'] = [];
     $this->connection->truncate('watchdog')->execute();
-    drupal_set_message($this->t('Database log cleared.'));
+    $this->messenger()->addStatus($this->t('Database log cleared.'));
     $form_state->setRedirectUrl($this->getCancelUrl());
   }
 
diff --git a/core/modules/field/field.module b/core/modules/field/field.module
index 14340b8bf0..4d4d4822fa 100644
--- a/core/modules/field/field.module
+++ b/core/modules/field/field.module
@@ -324,12 +324,12 @@ function field_form_config_admin_import_form_alter(&$form, FormStateInterface $f
       foreach ($field_storages as $field) {
         $field_labels[] = $field->label();
       }
-      drupal_set_message(\Drupal::translation()->formatPlural(
+      \Drupal::messenger()->addWarning(\Drupal::translation()->formatPlural(
         count($field_storages),
         'This synchronization will delete data from the field %fields.',
         'This synchronization will delete data from the fields: %fields.',
         ['%fields' => implode(', ', $field_labels)]
-      ), 'warning');
+      ));
     }
   }
 }
diff --git a/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module
index 9121e942ea..808c0acf8d 100644
--- a/core/modules/field/tests/modules/field_test/field_test.module
+++ b/core/modules/field/tests/modules/field_test/field_test.module
@@ -103,17 +103,17 @@ function field_test_field_widget_form_alter(&$element, FormStateInterface $form_
   $field_definition = $context['items']->getFieldDefinition();
   switch ($field_definition->getName()) {
     case 'alter_test_text':
-      drupal_set_message('Field size: ' . $context['widget']->getSetting('size'));
+      \Drupal::messenger()->addStatus('Field size: ' . $context['widget']->getSetting('size'));
       break;
 
     case 'alter_test_options':
-      drupal_set_message('Widget type: ' . $context['widget']->getPluginId());
+      \Drupal::messenger()->addStatus('Widget type: ' . $context['widget']->getPluginId());
       break;
   }
   // Set a message if this is for the form displayed to set default value for
   // the field.
   if ($context['default']) {
-    drupal_set_message('From hook_field_widget_form_alter(): Default form is true.');
+    \Drupal::messenger()->addStatus('From hook_field_widget_form_alter(): Default form is true.');
   }
 }
 
diff --git a/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php b/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php
index ed99a05e97..aed95dc929 100644
--- a/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php
+++ b/core/modules/field/tests/modules/field_test/src/Form/NestedEntityTestForm.php
@@ -92,7 +92,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
   }
 
   /**
-   * {@inheritdoc]
+   * {@inheritdoc}
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     /** @var \Drupal\Core\Entity\EntityInterface $entity_1 */
@@ -103,7 +103,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     $entity_2 = $form_state->get('entity_2');
     $entity_2->save();
 
-    drupal_set_message($this->t('test_entities @id_1 and @id_2 have been updated.', ['@id_1' => $entity_1->id(), '@id_2' => $entity_2->id()]));
+    $this->messenger()->addStatus($this->t('test_entities @id_1 and @id_2 have been updated.', ['@id_1' => $entity_1->id(), '@id_2' => $entity_2->id()]));
   }
 
 }
diff --git a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php
index 06eed1f9ac..71949a50bf 100644
--- a/core/modules/field_ui/src/Form/EntityDisplayFormBase.php
+++ b/core/modules/field_ui/src/Form/EntityDisplayFormBase.php
@@ -147,7 +147,7 @@ public function form(array $form, FormStateInterface $form_state) {
     ];
 
     if (empty($field_definitions) && empty($extra_fields) && $route_info = FieldUI::getOverviewRouteInfo($this->entity->getTargetEntityTypeId(), $this->entity->getTargetBundle())) {
-      drupal_set_message($this->t('There are no fields yet added. You can add new fields on the <a href=":link">Manage fields</a> page.', [':link' => $route_info->toString()]), 'warning');
+      $this->messenger()->addWarning($this->t('There are no fields yet added. You can add new fields on the <a href=":link">Manage fields</a> page.', [':link' => $route_info->toString()]));
       return $form;
     }
 
@@ -544,7 +544,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
 
           $display_mode_label = $display_modes[$mode]['label'];
           $url = $this->getOverviewUrl($mode);
-          drupal_set_message($this->t('The %display_mode mode now uses custom display settings. You might want to <a href=":url">configure them</a>.', ['%display_mode' => $display_mode_label, ':url' => $url->toString()]));
+          $this->messenger()->addStatus($this->t('The %display_mode mode now uses custom display settings. You might want to <a href=":url">configure them</a>.', ['%display_mode' => $display_mode_label, ':url' => $url->toString()]));
         }
         $statuses[$mode] = !empty($value);
       }
@@ -552,7 +552,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       $this->saveDisplayStatuses($statuses);
     }
 
-    drupal_set_message($this->t('Your settings have been saved.'));
+    $this->messenger()->addStatus($this->t('Your settings have been saved.'));
   }
 
   /**
diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php
index 72a8a19643..0e502f71b7 100644
--- a/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php
+++ b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php
@@ -78,7 +78,7 @@ public function exists($entity_id, array $element) {
    * {@inheritdoc}
    */
   public function save(array $form, FormStateInterface $form_state) {
-    drupal_set_message($this->t('Saved the %label @entity-type.', ['%label' => $this->entity->label(), '@entity-type' => $this->entityType->getLowercaseLabel()]));
+    $this->messenger()->addStatus($this->t('Saved the %label @entity-type.', ['%label' => $this->entity->label(), '@entity-type' => $this->entityType->getLowercaseLabel()]));
     $this->entity->save();
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     $form_state->setRedirectUrl($this->entity->urlInfo('collection'));
diff --git a/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php
index ab83e8fa35..efdecbfbfc 100644
--- a/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php
+++ b/core/modules/field_ui/src/Form/FieldConfigDeleteForm.php
@@ -98,10 +98,10 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
 
     if ($field_storage && !$field_storage->isLocked()) {
       $this->entity->delete();
-      drupal_set_message($this->t('The field %field has been deleted from the %type content type.', ['%field' => $this->entity->label(), '%type' => $bundle_label]));
+      $this->messenger()->addStatus($this->t('The field %field has been deleted from the %type content type.', ['%field' => $this->entity->label(), '%type' => $bundle_label]));
     }
     else {
-      drupal_set_message($this->t('There was a problem removing the %field from the %type content type.', ['%field' => $this->entity->label(), '%type' => $bundle_label]), 'error');
+      $this->messenger()->addError($this->t('There was a problem removing the %field from the %type content type.', ['%field' => $this->entity->label(), '%type' => $bundle_label]));
     }
 
     $form_state->setRedirectUrl($this->getCancelUrl());
diff --git a/core/modules/field_ui/src/Form/FieldConfigEditForm.php b/core/modules/field_ui/src/Form/FieldConfigEditForm.php
index 34868add47..bf19a4af2d 100644
--- a/core/modules/field_ui/src/Form/FieldConfigEditForm.php
+++ b/core/modules/field_ui/src/Form/FieldConfigEditForm.php
@@ -177,7 +177,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
   public function save(array $form, FormStateInterface $form_state) {
     $this->entity->save();
 
-    drupal_set_message($this->t('Saved %label configuration.', ['%label' => $this->entity->getLabel()]));
+    $this->messenger()->addStatus($this->t('Saved %label configuration.', ['%label' => $this->entity->getLabel()]));
 
     $request = $this->getRequest();
     if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
diff --git a/core/modules/field_ui/src/Form/FieldStorageAddForm.php b/core/modules/field_ui/src/Form/FieldStorageAddForm.php
index 584cc96846..5afd358a67 100644
--- a/core/modules/field_ui/src/Form/FieldStorageAddForm.php
+++ b/core/modules/field_ui/src/Form/FieldStorageAddForm.php
@@ -370,7 +370,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       }
       catch (\Exception $e) {
         $error = TRUE;
-        drupal_set_message($this->t('There was a problem creating field %label: @message', ['%label' => $values['label'], '@message' => $e->getMessage()]), 'error');
+        $this->messenger()->addError($this->t('There was a problem creating field %label: @message', ['%label' => $values['label'], '@message' => $e->getMessage()]));
       }
     }
 
@@ -401,7 +401,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       }
       catch (\Exception $e) {
         $error = TRUE;
-        drupal_set_message($this->t('There was a problem creating field %label: @message', ['%label' => $values['label'], '@message' => $e->getMessage()]), 'error');
+        $this->messenger()->addError($this->t('There was a problem creating field %label: @message', ['%label' => $values['label'], '@message' => $e->getMessage()]));
       }
     }
 
@@ -411,7 +411,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       $form_state->setRedirectUrl(FieldUI::getNextDestination($destinations, $form_state));
     }
     elseif (!$error) {
-      drupal_set_message($this->t('Your settings have been saved.'));
+      $this->messenger()->addStatus($this->t('Your settings have been saved.'));
     }
   }
 
diff --git a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
index 0ae5084c09..bce79d6af2 100644
--- a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
+++ b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php
@@ -222,7 +222,7 @@ public function save(array $form, FormStateInterface $form_state) {
     $field_label = $form_state->get('field_config')->label();
     try {
       $this->entity->save();
-      drupal_set_message($this->t('Updated field %label field settings.', ['%label' => $field_label]));
+      $this->messenger()->addStatus($this->t('Updated field %label field settings.', ['%label' => $field_label]));
       $request = $this->getRequest();
       if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) {
         $request->query->remove('destinations');
@@ -233,7 +233,7 @@ public function save(array $form, FormStateInterface $form_state) {
       }
     }
     catch (\Exception $e) {
-      drupal_set_message($this->t('Attempt to update field %label failed: %message.', ['%label' => $field_label, '%message' => $e->getMessage()]), 'error');
+      $this->messenger()->addStatus($this->t('Attempt to update field %label failed: %message.', ['%label' => $field_label, '%message' => $e->getMessage()]));
     }
   }
 
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index be1e136958..8a1fab1b44 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -8,6 +8,7 @@
 use Drupal\Core\Datetime\Entity\DateFormat;
 use Drupal\Core\Field\FieldDefinitionInterface;
 use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Messenger\MessengerInterface;
 use Drupal\Core\Render\BubbleableMetadata;
 use Drupal\Core\Render\Element;
 use Drupal\Core\Routing\RouteMatchInterface;
@@ -156,7 +157,7 @@ function file_copy(FileInterface $source, $destination = NULL, $replace = FILE_E
     else {
       \Drupal::logger('file')->notice('File %file could not be copied because the destination %destination is invalid. This is often caused by improper use of file_copy() or a missing stream wrapper.', ['%file' => $source->getFileUri(), '%destination' => $destination]);
     }
-    drupal_set_message(t('The specified file %file could not be copied because the destination is invalid. More information is available in the system log.', ['%file' => $source->getFileUri()]), 'error');
+    \Drupal::messenger()->addError(t('The specified file %file could not be copied because the destination is invalid. More information is available in the system log.', ['%file' => $source->getFileUri()]));
     return FALSE;
   }
 
@@ -231,7 +232,7 @@ function file_move(FileInterface $source, $destination = NULL, $replace = FILE_E
     else {
       \Drupal::logger('file')->notice('File %file could not be moved because the destination %destination is invalid. This may be caused by improper use of file_move() or a missing stream wrapper.', ['%file' => $source->getFileUri(), '%destination' => $destination]);
     }
-    drupal_set_message(t('The specified file %file could not be moved because the destination is invalid. More information is available in the system log.', ['%file' => $source->getFileUri()]), 'error');
+    \Drupal::messenger()->addError(t('The specified file %file could not be moved because the destination is invalid. More information is available in the system log.', ['%file' => $source->getFileUri()]));
     return FALSE;
   }
 
@@ -479,7 +480,7 @@ function file_validate_image_resolution(FileInterface $file, $maximum_dimensions
                 '%new_height' => $image->getHeight(),
               ]);
           }
-          drupal_set_message($message);
+          \Drupal::messenger()->addStatus($message);
         }
         else {
           $errors[] = t('The image exceeds the maximum allowed dimensions and an attempt to resize it failed.');
@@ -547,7 +548,7 @@ function file_save_data($data, $destination = NULL, $replace = FILE_EXISTS_RENAM
   }
   if (!file_valid_uri($destination)) {
     \Drupal::logger('file')->notice('The data could not be saved because the destination %destination is invalid. This may be caused by improper use of file_save_data() or a missing stream wrapper.', ['%destination' => $destination]);
-    drupal_set_message(t('The data could not be saved because the destination is invalid. More information is available in the system log.'), 'error');
+    \Drupal::messenger()->addError(t('The data could not be saved because the destination is invalid. More information is available in the system log.'));
     return FALSE;
   }
 
@@ -761,7 +762,7 @@ function file_cron() {
 function _file_save_upload_from_form(array $element, FormStateInterface $form_state, $delta = NULL, $replace = FILE_EXISTS_RENAME) {
   // Get all errors set before calling this method. This will also clear them
   // from $_SESSION.
-  $errors_before = drupal_get_messages('error');
+  $errors_before = \Drupal::messenger()->deleteByType(MessengerInterface::TYPE_ERROR);
 
   $upload_location = isset($element['#upload_location']) ? $element['#upload_location'] : FALSE;
   $upload_name = implode('_', $element['#parents']);
@@ -771,9 +772,8 @@ function _file_save_upload_from_form(array $element, FormStateInterface $form_st
 
   // Get new errors that are generated while trying to save the upload. This
   // will also clear them from $_SESSION.
-  $errors_new = drupal_get_messages('error');
-  if (!empty($errors_new['error'])) {
-    $errors_new = $errors_new['error'];
+  $errors_new = \Drupal::messenger()->deleteByType(MessengerInterface::TYPE_ERROR);
+  if (!empty($errors_new)) {
 
     if (count($errors_new) > 1) {
       // Render multiple errors into a single message.
@@ -798,9 +798,9 @@ function _file_save_upload_from_form(array $element, FormStateInterface $form_st
 
   // Ensure that errors set prior to calling this method are still shown to the
   // user.
-  if (!empty($errors_before['error'])) {
-    foreach ($errors_before['error'] as $error) {
-      drupal_set_message($error, 'error');
+  if (!empty($errors_before)) {
+    foreach ($errors_before as $error) {
+      \Drupal::messenger()->addError($error);
     }
   }
 
@@ -888,13 +888,13 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
     switch ($file_info->getError()) {
       case UPLOAD_ERR_INI_SIZE:
       case UPLOAD_ERR_FORM_SIZE:
-        drupal_set_message(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', ['%file' => $file_info->getFilename(), '%maxsize' => format_size(file_upload_max_size())]), 'error');
+        \Drupal::messenger()->addError(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', ['%file' => $file_info->getFilename(), '%maxsize' => format_size(file_upload_max_size())]));
         $files[$i] = FALSE;
         continue;
 
       case UPLOAD_ERR_PARTIAL:
       case UPLOAD_ERR_NO_FILE:
-        drupal_set_message(t('The file %file could not be saved because the upload did not complete.', ['%file' => $file_info->getFilename()]), 'error');
+        \Drupal::messenger()->addError(t('The file %file could not be saved because the upload did not complete.', ['%file' => $file_info->getFilename()]));
         $files[$i] = FALSE;
         continue;
 
@@ -907,7 +907,7 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
 
         // Unknown error
       default:
-        drupal_set_message(t('The file %file could not be saved. An unknown error has occurred.', ['%file' => $file_info->getFilename()]), 'error');
+        \Drupal::messenger()->addError(t('The file %file could not be saved. An unknown error has occurred.', ['%file' => $file_info->getFilename()]));
         $files[$i] = FALSE;
         continue;
 
@@ -962,7 +962,7 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
       // to add it here or else the file upload will fail.
       if (!empty($extensions)) {
         $validators['file_validate_extensions'][0] .= ' txt';
-        drupal_set_message(t('For security reasons, your upload has been renamed to %filename.', ['%filename' => $file->getFilename()]));
+        \Drupal::messenger()->addStatus(t('For security reasons, your upload has been renamed to %filename.', ['%filename' => $file->getFilename()]));
       }
     }
 
@@ -974,7 +974,7 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
     // Assert that the destination contains a valid stream.
     $destination_scheme = file_uri_scheme($destination);
     if (!file_stream_wrapper_valid_scheme($destination_scheme)) {
-      drupal_set_message(t('The file could not be uploaded because the destination %destination is invalid.', ['%destination' => $destination]), 'error');
+      \Drupal::messenger()->addError(t('The file could not be uploaded because the destination %destination is invalid.', ['%destination' => $destination]));
       $files[$i] = FALSE;
       continue;
     }
@@ -988,7 +988,7 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
     // If file_destination() returns FALSE then $replace === FILE_EXISTS_ERROR and
     // there's an existing file so we need to bail.
     if ($file->destination === FALSE) {
-      drupal_set_message(t('The file %source could not be uploaded because a file by that name already exists in the destination %directory.', ['%source' => $form_field_name, '%directory' => $destination]), 'error');
+      \Drupal::messenger()->addError(t('The file %source could not be uploaded because a file by that name already exists in the destination %directory.', ['%source' => $form_field_name, '%directory' => $destination]));
       $files[$i] = FALSE;
       continue;
     }
@@ -1012,7 +1012,7 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
       ];
       // @todo Add support for render arrays in drupal_set_message()? See
       //  https://www.drupal.org/node/2505497.
-      drupal_set_message(\Drupal::service('renderer')->renderPlain($message), 'error');
+      \Drupal::messenger()->addError(\Drupal::service('renderer')->renderPlain($message));
       $files[$i] = FALSE;
       continue;
     }
@@ -1022,7 +1022,7 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
     // operations.
     $file->setFileUri($file->destination);
     if (!drupal_move_uploaded_file($file_info->getRealPath(), $file->getFileUri())) {
-      drupal_set_message(t('File upload error. Could not move uploaded file.'), 'error');
+      \Drupal::messenger()->addError(t('File upload error. Could not move uploaded file.'));
       \Drupal::logger('file')->notice('Upload error. Could not move uploaded file %file to destination %destination.', ['%file' => $file->getFilename(), '%destination' => $file->getFileUri()]);
       $files[$i] = FALSE;
       continue;
diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
index 587a396fc6..f1da5a4b5f 100644
--- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
+++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php
@@ -365,7 +365,7 @@ public static function validateMultipleCount($element, FormStateInterface $form_
         '%list' => implode(', ', $removed_names),
       ];
       $message = t('Field %field can only hold @max values but there were @count uploaded. The following files have been omitted as a result: %list.', $args);
-      drupal_set_message($message, 'warning');
+      \Drupal::messenger()->addWarning($message);
       $values['fids'] = array_slice($values['fids'], 0, $keep);
       NestedArray::setValue($form_state->getValues(), $element['#parents'], $values);
     }
diff --git a/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php b/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php
index 51353f6381..78b6e7d05d 100644
--- a/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php
+++ b/core/modules/file/tests/file_module_test/src/Form/FileModuleTestForm.php
@@ -85,7 +85,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
       $fids[] = $fid;
     }
 
-    drupal_set_message($this->t('The file ids are %fids.', ['%fids' => implode(',', $fids)]));
+    \Drupal::messenger()->addStatus($this->t('The file ids are %fids.', ['%fids' => implode(',', $fids)]));
   }
 
 }
diff --git a/core/modules/file/tests/file_test/src/Form/FileTestForm.php b/core/modules/file/tests/file_test/src/Form/FileTestForm.php
index f43e20a8e9..42a5dd9280 100644
--- a/core/modules/file/tests/file_test/src/Form/FileTestForm.php
+++ b/core/modules/file/tests/file_test/src/Form/FileTestForm.php
@@ -108,13 +108,13 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     $file = file_save_upload('file_test_upload', $validators, $destination, 0, $form_state->getValue('file_test_replace'));
     if ($file) {
       $form_state->setValue('file_test_upload', $file);
-      drupal_set_message(t('File @filepath was uploaded.', ['@filepath' => $file->getFileUri()]));
-      drupal_set_message(t('File name is @filename.', ['@filename' => $file->getFilename()]));
-      drupal_set_message(t('File MIME type is @mimetype.', ['@mimetype' => $file->getMimeType()]));
-      drupal_set_message(t('You WIN!'));
+      \Drupal::messenger()->addStatus(t('File @filepath was uploaded.', ['@filepath' => $file->getFileUri()]));
+      \Drupal::messenger()->addStatus(t('File name is @filename.', ['@filename' => $file->getFilename()]));
+      \Drupal::messenger()->addStatus(t('File MIME type is @mimetype.', ['@mimetype' => $file->getMimeType()]));
+      \Drupal::messenger()->addStatus(t('You WIN!'));
     }
     elseif ($file === FALSE) {
-      drupal_set_message(t('Epic upload FAIL!'), 'error');
+      \Drupal::messenger()->addError(t('Epic upload FAIL!'));
     }
   }
 
diff --git a/core/modules/file/tests/file_test/src/Form/FileTestSaveUploadFromForm.php b/core/modules/file/tests/file_test/src/Form/FileTestSaveUploadFromForm.php
index 97cd9505fc..e992c678b2 100644
--- a/core/modules/file/tests/file_test/src/Form/FileTestSaveUploadFromForm.php
+++ b/core/modules/file/tests/file_test/src/Form/FileTestSaveUploadFromForm.php
@@ -117,7 +117,7 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
 
     // Preset custom error message if requested.
     if ($form_state->getValue('error_message')) {
-      drupal_set_message($form_state->getValue('error_message'), 'error');
+      $this->messenger()->addError($form_state->getValue('error_message'));
     }
 
     // Setup validators.
@@ -143,19 +143,19 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
     $form['file_test_upload']['#upload_validators'] = $validators;
     $form['file_test_upload']['#upload_location'] = $destination;
 
-    drupal_set_message($this->t('Number of error messages before _file_save_upload_from_form(): @count.', ['@count' => count(drupal_get_messages('error', FALSE))]));
+    $this->messenger()->addStatus($this->t('Number of error messages before _file_save_upload_from_form(): @count.', ['@count' => count($this->messenger()->messagesByType('error'))]));
     $file = _file_save_upload_from_form($form['file_test_upload'], $form_state, 0, $form_state->getValue('file_test_replace'));
-    drupal_set_message($this->t('Number of error messages after _file_save_upload_from_form(): @count.', ['@count' => count(drupal_get_messages('error', FALSE))]));
+    $this->messenger()->addStatus($this->t('Number of error messages after _file_save_upload_from_form(): @count.', ['@count' => count($this->messenger()->messagesByType('error'))]));
 
     if ($file) {
       $form_state->setValue('file_test_upload', $file);
-      drupal_set_message($this->t('File @filepath was uploaded.', ['@filepath' => $file->getFileUri()]));
-      drupal_set_message($this->t('File name is @filename.', ['@filename' => $file->getFilename()]));
-      drupal_set_message($this->t('File MIME type is @mimetype.', ['@mimetype' => $file->getMimeType()]));
-      drupal_set_message($this->t('You WIN!'));
+      $this->messenger()->addStatus($this->t('File @filepath was uploaded.', ['@filepath' => $file->getFileUri()]));
+      $this->messenger()->addStatus($this->t('File name is @filename.', ['@filename' => $file->getFilename()]));
+      $this->messenger()->addStatus($this->t('File MIME type is @mimetype.', ['@mimetype' => $file->getMimeType()]));
+      $this->messenger()->addStatus($this->t('You WIN!'));
     }
     elseif ($file === FALSE) {
-      drupal_set_message($this->t('Epic upload FAIL!'), 'error');
+      $this->messenger()->addError($this->t('Epic upload FAIL!'));
     }
   }
 
diff --git a/core/modules/filter/src/FilterFormatAddForm.php b/core/modules/filter/src/FilterFormatAddForm.php
index 39f1cb610b..07a7d0a415 100644
--- a/core/modules/filter/src/FilterFormatAddForm.php
+++ b/core/modules/filter/src/FilterFormatAddForm.php
@@ -23,7 +23,7 @@ public function form(array $form, FormStateInterface $form_state) {
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     parent::submitForm($form, $form_state);
-    drupal_set_message($this->t('Added text format %format.', ['%format' => $this->entity->label()]));
+    $this->messenger()->addStatus($this->t('Added text format %format.', ['%format' => $this->entity->label()]));
     return $this->entity;
   }
 
diff --git a/core/modules/filter/src/FilterFormatEditForm.php b/core/modules/filter/src/FilterFormatEditForm.php
index 8173a785c0..b8decc138f 100644
--- a/core/modules/filter/src/FilterFormatEditForm.php
+++ b/core/modules/filter/src/FilterFormatEditForm.php
@@ -31,7 +31,7 @@ public function form(array $form, FormStateInterface $form_state) {
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     parent::submitForm($form, $form_state);
-    drupal_set_message($this->t('The text format %format has been updated.', ['%format' => $this->entity->label()]));
+    $this->messenger()->addStatus($this->t('The text format %format has been updated.', ['%format' => $this->entity->label()]));
     return $this->entity;
   }
 
diff --git a/core/modules/filter/src/FilterFormatFormBase.php b/core/modules/filter/src/FilterFormatFormBase.php
index cbcb632189..5526b02fd4 100644
--- a/core/modules/filter/src/FilterFormatFormBase.php
+++ b/core/modules/filter/src/FilterFormatFormBase.php
@@ -64,7 +64,7 @@ public function form(array $form, FormStateInterface $form_state) {
       // When a filter is missing, it is replaced by the null filter. Remove it
       // here, so that saving the form will remove the missing filter.
       if ($filter instanceof FilterNull) {
-        drupal_set_message($this->t('The %filter filter is missing, and will be removed once this format is saved.', ['%filter' => $filter_id]), 'warning');
+        $this->messenger()->addWarning($this->t('The %filter filter is missing, and will be removed once this format is saved.', ['%filter' => $filter_id]));
         $filters->removeInstanceID($filter_id);
       }
     }
diff --git a/core/modules/filter/src/FilterFormatListBuilder.php b/core/modules/filter/src/FilterFormatListBuilder.php
index cf084564c0..ca34dfdd6e 100644
--- a/core/modules/filter/src/FilterFormatListBuilder.php
+++ b/core/modules/filter/src/FilterFormatListBuilder.php
@@ -150,7 +150,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     parent::submitForm($form, $form_state);
 
     filter_formats_reset();
-    drupal_set_message($this->t('The text format ordering has been saved.'));
+    $this->messenger()->addStatus($this->t('The text format ordering has been saved.'));
   }
 
 }
diff --git a/core/modules/filter/src/Form/FilterDisableForm.php b/core/modules/filter/src/Form/FilterDisableForm.php
index a8a2ba3aad..0c213a2666 100644
--- a/core/modules/filter/src/Form/FilterDisableForm.php
+++ b/core/modules/filter/src/Form/FilterDisableForm.php
@@ -46,7 +46,7 @@ public function getDescription() {
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $this->entity->disable()->save();
-    drupal_set_message($this->t('Disabled text format %format.', ['%format' => $this->entity->label()]));
+    $this->messenger()->addStatus($this->t('Disabled text format %format.', ['%format' => $this->entity->label()]));
 
     $form_state->setRedirectUrl($this->getCancelUrl());
   }
diff --git a/core/modules/filter/tests/filter_test/filter_test.module b/core/modules/filter/tests/filter_test/filter_test.module
index e3983b4f32..27fedcb7d5 100644
--- a/core/modules/filter/tests/filter_test/filter_test.module
+++ b/core/modules/filter/tests/filter_test/filter_test.module
@@ -9,19 +9,19 @@
  * Implements hook_filter_format_insert().
  */
 function filter_test_filter_format_insert($format) {
-  drupal_set_message('hook_filter_format_insert invoked.');
+  \Drupal::messenger()->addStatus('hook_filter_format_insert invoked.');
 }
 
 /**
  * Implements hook_filter_format_update().
  */
 function filter_test_filter_format_update($format) {
-  drupal_set_message('hook_filter_format_update invoked.');
+  \Drupal::messenger()->addStatus('hook_filter_format_update invoked.');
 }
 
 /**
  * Implements hook_filter_format_disable().
  */
 function filter_test_filter_format_disable($format) {
-  drupal_set_message('hook_filter_format_disable invoked.');
+  \Drupal::messenger()->addStatus('hook_filter_format_disable invoked.');
 }
diff --git a/core/modules/forum/src/Form/DeleteForm.php b/core/modules/forum/src/Form/DeleteForm.php
index c65241019a..4cf56c3283 100644
--- a/core/modules/forum/src/Form/DeleteForm.php
+++ b/core/modules/forum/src/Form/DeleteForm.php
@@ -63,7 +63,7 @@ public function buildForm(array $form, FormStateInterface $form_state, TermInter
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
     $this->taxonomyTerm->delete();
-    drupal_set_message($this->t('The forum %label and all sub-forums have been deleted.', ['%label' => $this->taxonomyTerm->label()]));
+    $this->messenger()->addStatus($this->t('The forum %label and all sub-forums have been deleted.', ['%label' => $this->taxonomyTerm->label()]));
     $this->logger('forum')->notice('forum: deleted %label and all its sub-forums.', ['%label' => $this->taxonomyTerm->label()]);
     $form_state->setRedirectUrl($this->getCancelUrl());
   }
diff --git a/core/modules/forum/src/Form/ForumForm.php b/core/modules/forum/src/Form/ForumForm.php
index c894d3fbb3..28030cb9f7 100644
--- a/core/modules/forum/src/Form/ForumForm.php
+++ b/core/modules/forum/src/Form/ForumForm.php
@@ -82,13 +82,13 @@ public function save(array $form, FormStateInterface $form_state) {
     $view_link = $term->link($term->getName());
     switch ($status) {
       case SAVED_NEW:
-        drupal_set_message($this->t('Created new @type %term.', ['%term' => $view_link, '@type' => $this->forumFormType]));
+        $this->messenger()->addStatus($this->t('Created new @type %term.', ['%term' => $view_link, '@type' => $this->forumFormType]));
         $this->logger('forum')->notice('Created new @type %term.', ['%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => $link]);
         $form_state->setValue('tid', $term->id());
         break;
 
       case SAVED_UPDATED:
-        drupal_set_message($this->t('The @type %term has been updated.', ['%term' => $term->getName(), '@type' => $this->forumFormType]));
+        $this->messenger()->addStatus($this->t('The @type %term has been updated.', ['%term' => $term->getName(), '@type' => $this->forumFormType]));
         $this->logger('forum')->notice('Updated @type %term.', ['%term' => $term->getName(), '@type' => $this->forumFormType, 'link' => $link]);
         break;
     }
