diff --git a/node_reference/node_reference.module b/node_reference/node_reference.module
index 1752cd7..1902933 100644
--- a/node_reference/node_reference.module
+++ b/node_reference/node_reference.module
@@ -552,6 +552,7 @@ function node_reference_field_widget_form(&$form, &$form_state, $field, $instanc
         '#default_value' => isset($items[$delta]['nid']) ? $items[$delta]['nid'] : NULL,
         '#autocomplete_path' => $instance['widget']['settings']['autocomplete_path'] . '/' . $instance['entity_type'] . '/' . $instance['bundle'] . '/' . $field['field_name'],
         '#size' => $instance['widget']['settings']['size'],
+        '#maxlength' => 255,
         '#element_validate' => array('node_reference_autocomplete_validate'),
         '#value_callback' => 'node_reference_autocomplete_value',
       );
@@ -579,8 +580,8 @@ function node_reference_autocomplete_value($element, $input = FALSE, $form_state
         ->range(0, 1);
       $result = $q->execute();
       // @todo If no result (node doesn't exist or no access).
-      $value = $result->fetchField();
-      $value .= ' [nid:' . $nid . ']';
+      $title = $result->fetchField();
+      $value = node_reference_field_safe_value($title, $nid);
       return $value;
     }
   }
@@ -609,7 +610,7 @@ function node_reference_autocomplete_validate($element, &$form_state, $form) {
           ->condition('n.nid', $nid)
           ->execute()
           ->fetchField();
-        if (trim($title) != trim($real_title)) {
+        if (trim($title) != node_reference_field_safe_value($real_title, $nid, TRUE)) {
           form_error($element, t('%name: title mismatch. Please check your selection.', array('%name' => $instance['label'])));
         }
       }
@@ -831,7 +832,7 @@ function node_reference_autocomplete($entity_type, $bundle, $field_name, $string
     // through Views) but we want to remove hyperlinks.
     $suggestion = preg_replace('/<a href="([^<]*)">([^<]*)<\/a>/', '$2', $row['rendered']);
     // Add a class wrapper for a few required CSS overrides.
-    $matches[$row['title'] . " [nid:$id]"] = '<div class="reference-autocomplete">' . $suggestion . '</div>';
+    $matches[node_reference_field_safe_value($row['title'], $id)] = '<div class="reference-autocomplete">' . $suggestion . '</div>';
   }
 
   drupal_json_output($matches);
@@ -1101,3 +1102,32 @@ function node_reference_views_options($field_name) {
   }
   return array();
 }
+
+/**
+ * Used to ensure that the value is never more than 255 characters.
+ *
+ * @param $title
+ *  The string title of the node.
+ * @param $nid
+ *  The nid of the node.
+ * @param $title_only
+ *  Boolean value used to determine if only the safe title should be returned.
+ *
+ * @return string
+ *  Either the full field value or only the title will be returned.
+ */
+function node_reference_field_safe_value($title, $nid, $title_only = FALSE) {
+  $safe_title = $title = trim($title);
+  $value = $title . " [nid:$nid]";
+
+  $value_length = strlen($value);
+  if ($value_length > 255) {
+    $safe_title = truncate_utf8($safe_title, 255+255-$value_length);
+    $value = $safe_title . " [nid:$nid]";
+  }
+
+  if ($title_only) {
+    $value = $safe_title;
+  }
+  return $value;
+}
