diff --git a/core/lib/Drupal/Core/CoreBundle.php b/core/lib/Drupal/Core/CoreBundle.php
index 2d85f6a..b8b65e3 100644
--- a/core/lib/Drupal/Core/CoreBundle.php
+++ b/core/lib/Drupal/Core/CoreBundle.php
@@ -16,6 +16,7 @@
 use Drupal\Core\DependencyInjection\Compiler\RegisterRouteEnhancersPass;
 use Drupal\Core\DependencyInjection\Compiler\RegisterParamConvertersPass;
 use Drupal\Core\DependencyInjection\Compiler\RegisterServicesForDestructionPass;
+use Drupal\Core\DependencyInjection\Compiler\RegisterTwigExtensionsPass;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 use Symfony\Component\DependencyInjection\Reference;
@@ -60,6 +61,8 @@ public function build(ContainerBuilder $container) {
     // Add the compiler pass that will process the tagged services.
     $container->addCompilerPass(new RegisterPathProcessorsPass());
     $container->addCompilerPass(new ListCacheBinsPass());
+    // Register Twig extensions.
+    $container->addCompilerPass(new RegisterTwigExtensionsPass());
   }
 
   /**
diff --git a/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterTwigExtensionsPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterTwigExtensionsPass.php
new file mode 100644
index 0000000..09876b0
--- /dev/null
+++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterTwigExtensionsPass.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\Core\DependencyInjection\Compiler\RegisterTwigExtensionsPass.
+ */
+
+namespace Drupal\Core\DependencyInjection\Compiler;
+
+use InvalidArgumentException;
+use ReflectionClass;
+use Twig_Extension;
+use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+
+class RegisterTwigExtensionsPass implements CompilerPassInterface {
+  public function process(ContainerBuilder $container) {
+    if (!$container->hasDefinition('twig')) {
+      return;
+    }
+
+    $definition = $container->getDefinition('twig');
+
+    foreach ($container->findTaggedServiceIds('twig.extension') as $id => $attributes) {
+      // We must assume that the class value has been correcly filled, even if the service is created by a factory
+      $class = $container->getDefinition($id)->getClass();
+
+      $refClass = new ReflectionClass($class);
+      $interface = 'Twig_ExtensionInterface';
+      if (!$refClass->implementsInterface($interface)) {
+        throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
+      }
+      $definition->addMethodCall('addExtension', array(new Reference($id)));
+    }
+  }
+}
diff --git a/core/modules/system/lib/Drupal/system/Tests/Theme/TwigExtensionTest.php b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigExtensionTest.php
new file mode 100644
index 0000000..010825e
--- /dev/null
+++ b/core/modules/system/lib/Drupal/system/Tests/Theme/TwigExtensionTest.php
@@ -0,0 +1,96 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\system\Tests\Theme\TwigExtensionTest.
+ */
+
+namespace Drupal\system\Tests\Theme;
+
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests Twig engine configuration via settings.php.
+ */
+class TwigExtensionTest extends WebTestBase {
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('theme_test', 'twig_theme_test', 'twig_extension_test');
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Twig Extension',
+      'description' => 'Tests Twig extensions.',
+      'group' => 'Theme',
+    );
+  }
+
+  function setUp() {
+    parent::setUp();
+    theme_enable(array('test_theme_twig'));
+  }
+
+  /**
+   * Tests that the provided Twig extension loads the service appropriately.
+   */
+  function testTwigExtensionLoaded() {
+    $twigService = \Drupal::service('twig');
+    $ext = $twigService->getExtension('twig_extension_test.test_extension');
+    $this->assertEqual(
+      get_class($ext), 
+      'Drupal\twig_extension_test\TwigExtension\TestExtension', 
+      'TestExtension loaded successfully.'
+    );
+  }
+
+  /**
+   * Tests that the Twig extension's filter produces expected output.
+   */
+  function testTwigExtensionFilter() {
+    config('system.theme')
+      ->set('default', 'test_theme_twig')
+      ->save();
+
+    $this->drupalGet('twig-extension-test/filter');
+    $this->assertNoText(
+      'If you are seeing this, the theme is still using phptemplate and the test has failed.', 
+      'Success: Using Twig template.'
+    );
+    $this->assertText(
+      'Every plant is not a mineral.', 
+      'Success: String filtered.'
+    );
+  }
+
+  /**
+   * Tests that the Twig extension's function produces expected output.
+   */
+  function testTwigExtensionFunction() {
+    config('system.theme')
+      ->set('default', 'test_theme_twig')
+      ->save();
+
+    $out = $this->drupalGet('twig-extension-test/function');
+    $this->assertNoText(
+      'If you are seeing this, the theme is still using phptemplate and the test has failed.', 
+      'Success: Using Twig template.'
+    );
+    $this->assertText(
+      'THE QUICK BROWN BOX JUMPS OVER THE LAZY DOG 123.', 
+      'Success: Text converted to uppercase.'
+    );
+    $this->assertText(
+      'the quick brown box jumps over the lazy dog 123.', 
+      'Success: Text converted to lowercase.'
+    );
+    $this->assertNoText(
+      'The Quick Brown Fox Jumps Over The Lazy Dog 123.', 
+      'Success: No text left behind.'
+    );
+  }
+
+}
diff --git a/core/modules/system/tests/modules/twig_extension_test/lib/Drupal/twig_extension_test/TwigExtension/TestExtension.php b/core/modules/system/tests/modules/twig_extension_test/lib/Drupal/twig_extension_test/TwigExtension/TestExtension.php
new file mode 100644
index 0000000..a9952e9
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_extension_test/lib/Drupal/twig_extension_test/TwigExtension/TestExtension.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Drupal\twig_extension_test\TwigExtension;
+
+use Drupal\Core\Template\TwigExtension;
+use Drupal\Core\Template\TwigReferenceFunction;
+
+class TestExtension extends TwigExtension {
+  public function getFunctions() {
+    return array(
+      'testfunc' => new \Twig_Function_Function(
+        array('Drupal\twig_extension_test\TwigExtension\TestExtension', 'testFunction')
+      ),
+    );
+  }
+
+  public function getFilters() {
+    return array(
+      'testfilter' => new \Twig_Filter_Function(
+        array('Drupal\twig_extension_test\TwigExtension\TestExtension', 'testFilter')
+      ),
+    );
+  }
+
+  public function getName() {
+    return 'twig_extension_test.test_extension';
+  }
+
+  /* Custom functions & filters */
+
+  public static function testFilter ($string) {
+    return str_replace(array('animal'), array('plant'), $string);
+  }
+
+  public static function testFunction ($upperCase = FALSE) {
+    $string = "The quick brown box jumps over the lazy dog 123.";
+    if ($upperCase == TRUE) {
+      return strtoupper($string);
+    }
+    else {
+      return strtolower($string);
+    }
+  }
+}
+
diff --git a/core/modules/system/tests/modules/twig_extension_test/lib/Drupal/twig_extension_test/TwigExtensionTestController.php b/core/modules/system/tests/modules/twig_extension_test/lib/Drupal/twig_extension_test/TwigExtensionTestController.php
new file mode 100644
index 0000000..aa772b8
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_extension_test/lib/Drupal/twig_extension_test/TwigExtensionTestController.php
@@ -0,0 +1,41 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\twig_extension_test\TwigExtensionTestController.
+ */
+
+namespace Drupal\twig_extension_test;
+
+use Drupal\Core\ControllerInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+/**
+ * Controller routines for Twig theme test routes.
+ */
+class TwigExtensionTestController implements ControllerInterface {
+
+  /**
+   * Creates the controller.
+   */
+  public static function create(ContainerInterface $container) {
+    return new static();
+  }
+
+  /**
+   * Menu callback for testing Twig filters in a Twig template.
+   */
+  public function testFilterRender() {
+    return theme('twig_extension_test_filter', array(
+      'message' => 'Every animal is not a mineral.',
+    ));
+  }
+
+  /**
+   * Menu callback for testing Twig functions in a Twig template.
+   */
+  public function testFunctionRender() {
+    return theme('twig_extension_test_function');
+  }
+
+}
diff --git a/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.filter.html.twig b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.filter.html.twig
new file mode 100644
index 0000000..1e224d0
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.filter.html.twig
@@ -0,0 +1,3 @@
+<div class="testfilter">
+  {{ message|testfilter }}
+</div>
diff --git a/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.filter.tpl.php b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.filter.tpl.php
new file mode 100644
index 0000000..153ec2b
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.filter.tpl.php
@@ -0,0 +1,3 @@
+<p>
+  If you are seeing this, the theme is still using phptemplate and the test has failed.
+</p>
\ No newline at end of file
diff --git a/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.function.html.twig b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.function.html.twig
new file mode 100644
index 0000000..76e870f
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.function.html.twig
@@ -0,0 +1,7 @@
+<div class="testfunction">
+  {{ testfunc(1) }}
+</div>
+
+<div class="testfunction">
+  {{ testfunc(0) }}
+</div>
diff --git a/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.function.tpl.php b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.function.tpl.php
new file mode 100644
index 0000000..153ec2b
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_extension_test/templates/twig_extension_test.function.tpl.php
@@ -0,0 +1,3 @@
+<p>
+  If you are seeing this, the theme is still using phptemplate and the test has failed.
+</p>
\ No newline at end of file
diff --git a/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.info.yml b/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.info.yml
new file mode 100644
index 0000000..270352f
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.info.yml
@@ -0,0 +1,7 @@
+name: 'Twig Extension Test'
+type: module
+description: 'Support module for testing Twig extensions.'
+package: Testing
+version: VERSION
+core: 8.x
+hidden: true
diff --git a/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.module b/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.module
new file mode 100644
index 0000000..bbbf2a0
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.module
@@ -0,0 +1,17 @@
+<?php
+
+/**
+ * Implements hook_theme().
+ */
+function twig_extension_test_theme($existing, $type, $theme, $path) {
+  return array(
+    'twig_extension_test_filter' => array(
+      'variables' => array('message' => NULL), 
+      'template' => 'twig_extension_test.filter',
+    ),
+    'twig_extension_test_function' => array(
+      'template' => 'twig_extension_test.function',
+    ),
+  );
+}
+
diff --git a/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.routing.yml b/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.routing.yml
new file mode 100644
index 0000000..8d4bace
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.routing.yml
@@ -0,0 +1,12 @@
+twig_extension_test.filter:
+  pattern: '/twig-extension-test/filter'
+  defaults:
+    _content: '\Drupal\twig_extension_test\TwigExtensionTestController::testFilterRender'
+  requirements:
+    _permission: 'access content'
+twig_extension_test.function:
+  pattern: '/twig-extension-test/function'
+  defaults:
+    _content: '\Drupal\twig_extension_test\TwigExtensionTestController::testFunctionRender'
+  requirements:
+    _permission: 'access content'
diff --git a/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.services.yml b/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.services.yml
new file mode 100644
index 0000000..8784c0f
--- /dev/null
+++ b/core/modules/system/tests/modules/twig_extension_test/twig_extension_test.services.yml
@@ -0,0 +1,5 @@
+services:
+  twig_extension_test.twig.test_extension:
+    class: Drupal\twig_extension_test\TwigExtension\TestExtension
+    tags:
+      - { name: twig.extension }
