diff --git a/panels.module b/panels.module
index 6374d17..68e59cd 100644
--- a/panels.module
+++ b/panels.module
@@ -1233,22 +1233,28 @@ function panels_export_display($display, $prefix = '') {
   // Initialize empty properties.
   $output .= $prefix . '$display->content = array()' . ";\n";
   $output .= $prefix . '$display->panels = array()' . ";\n";
-  $panels = array();
 
   $title_pid = 0;
   if (!empty($display->content)) {
     $region_counters = array();
-    foreach ($display->content as $pane) {
+    $display_content = $display->content;
 
+    // Set pane uuid and pid.
+    foreach ($display_content as $pane) {
       if (!isset($pane->uuid) || !ctools_uuid_is_valid($pane->uuid)) {
         $pane->uuid = ctools_uuid_generate();
       }
-      $pid = 'new-' . $pane->uuid;
+      $pane->pid = 'new-' . $pane->uuid;
+    }
+
+    // Sort panes on panel, position, uuid.
+    usort($display_content, '_panels_pane_compare');
 
+    // Export each pane to $output.
+    foreach ($display_content as $pane) {
       if ($pane->pid == $display->title_pane) {
-        $title_pid = $pid;
+        $title_pid = $pane->pid;
       }
-      $pane->pid = $pid;
       $output .= ctools_export_object('panels_pane', $pane, $prefix);
       $output .= $prefix . '$display->content[\'' . $pane->pid . '\'] = $pane' . ";\n";
       if (!isset($region_counters[$pane->panel])) {
@@ -1277,6 +1283,33 @@ function panels_export_display($display, $prefix = '') {
   return $output;
 }
 
+/**
+ * Compare panes on panel, position and uuid.
+ *
+ * Use with usort().
+ *
+ * @see panels_export_display().
+ *
+ * @param object $panea
+ *   First panel.
+ * @param object $paneb
+ *   Second panel.
+ * @return int
+ *   Negative when $panea is less than $paneb.
+ *   0 when $panea and $paneb are equal in panel, position and uuid.
+ *   Positive when $panea is greater than $paneb.
+ */
+function _panels_pane_compare($panea, $paneb) {
+  if ($panea->panel !== $paneb->panel) {
+    return strcmp($panea->panel, $paneb->panel);
+  }
+  if ($panea->position != $paneb->position) {
+    return $panea->position - $paneb->position;
+  }
+
+  return strcmp($panea->uuid, $paneb->uuid);
+}
+
 /**
  * Panels Render Display.
  *
