diff --git a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php
index 2f7a61970f5332dff2adab9ca151b8b489e4fd5c..04396779c4da5fd5f9984177fbb06cbfbda16f22 100644
--- a/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php
+++ b/module/VuFind/src/VuFind/Controller/Plugin/ResultScroller.php
@@ -88,6 +88,7 @@ class ResultScroller extends AbstractPlugin
         $this->data->searchId = $searchObject->getSearchId();
         $this->data->page = $searchObject->getParams()->getPage();
         $this->data->limit = $searchObject->getParams()->getLimit();
+        $this->data->sort = $searchObject->getParams()->getSort();
         $this->data->total = $searchObject->getResultTotal();
         $this->data->firstlast = $searchObject->getOptions()
             ->supportsFirstLastNavigation();
@@ -524,7 +525,7 @@ class ResultScroller extends AbstractPlugin
      */
     protected function fetchPage($searchObject, $page = null)
     {
-        if (!is_null($page)) {
+        if (null !== $page) {
             $searchObject->getParams()->setPage($page);
             $searchObject->performAndProcessSearch();
         }
@@ -558,6 +559,7 @@ class ResultScroller extends AbstractPlugin
                 // The saved search does not remember its original limit;
                 // we should reapply it from the session data:
                 $search->getParams()->setLimit($this->data->limit);
+                $search->getParams()->setSort($this->data->sort);
                 return $search;
             }
         }
diff --git a/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php b/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php
index 473d3fef7f4b8a303f8823e35369d0694ed599fa..374690efd25096bd2a0298f7a726970f68afd266 100644
--- a/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php
+++ b/module/VuFind/src/VuFindTest/Search/TestHarness/Results.php
@@ -100,7 +100,10 @@ class Results extends \VuFind\Search\Base\Results
             if ($i > $this->resultTotal) {
                 break;
             }
-            $this->results[] = $this->getMockRecordDriver($i);
+            // Append sort type to ID to simulate sort order; default sort is
+            // null, so most tests will just get numbers.
+            $sort = $this->getParams()->getSort();
+            $this->results[] = $this->getMockRecordDriver($sort . $i);
         }
     }
 
diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php
index 40258c91ff4c0c52af29f96e0e2d0b2ad79a4ec2..2a7c3953639e0737c271388efc31ef4d29c258e5 100644
--- a/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php
+++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Controller/Plugin/ResultScrollerTest.php
@@ -290,18 +290,39 @@ class ResultScrollerTest extends TestCase
         $this->assertEquals($expected, $plugin->getScrollData($results->getMockRecordDriver(20)));
     }
 
+    /**
+     * Test scrolling at end of middle page with sorting.
+     *
+     * @return void
+     */
+    public function testScrollingAtEndOfMiddlePageWithSorting()
+    {
+        $results = $this->getMockResults(2, 10, 30, true, 'sorted');
+        $plugin = $this->getMockResultScroller($results);
+        $this->assertTrue($plugin->init($results));
+        $expected = [
+            'firstRecord' => 'Solr|sorted1', 'lastRecord' => 'Solr|sorted30',
+            'previousRecord' => 'Solr|sorted19', 'nextRecord' => 'Solr|sorted21',
+            'currentPosition' => 20, 'resultTotal' => 30
+        ];
+        $this->assertEquals($expected, $plugin->getScrollData(
+            $results->getMockRecordDriver('sorted20'))
+        );
+    }
+
     /**
      * Get mock search results
      *
-     * @param int  $page      Current page number
-     * @param int  $limit     Page size
-     * @param int  $total     Total size of fake result set
-     * @param bool $firstLast Turn on first/last config?
+     * @param int    $page      Current page number
+     * @param int    $limit     Page size
+     * @param int    $total     Total size of fake result set
+     * @param bool   $firstLast Turn on first/last config?
+     * @param string $sort      Sort type (null for default)
      *
      * @return \VuFind\Search\Base\Results
      */
     protected function getMockResults($page = 1, $limit = 20, $total = 0,
-        $firstLast = true
+        $firstLast = true, $sort = null
     ) {
         $pm = $this->getMockBuilder('VuFind\Config\PluginManager')->disableOriginalConstructor()->getMock();
         $config = new \Zend\Config\Config(
@@ -312,6 +333,9 @@ class ResultScrollerTest extends TestCase
         $params = new \VuFindTest\Search\TestHarness\Params($options, $pm);
         $params->setPage($page);
         $params->setLimit($limit);
+        if (null !== $sort) {
+            $params->setSort($sort, true);
+        }
         $results = new \VuFindTest\Search\TestHarness\Results($params, $total);
         return $results;
     }