diff --git a/ChangeLog b/ChangeLog
index dc54b9efa2622eca6f89d41abe4668ee3eb6fe0f..ece4487983f6699214e04318c3c1c348a4cbbdc6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -42,9 +42,10 @@ CVS code -
 	  feature is disabled if justification is disabled. (DLR)
 	- Modify the justification algorithm to work the same way as in
 	  the current version of Pico, i.e, add a space at the end of
-	  each line of the justified paragraph except for the last one.
-	  Changes to justify_format() and do_justify().  (Note that the
-	  addition of spaces to justified lines means that
+	  each line of the justified paragraph except for the last one,
+	  and if there was a space at the end of the last one, remove
+	  it.  Changes to justify_format() and do_justify().  (Note that
+	  the addition of spaces to justified lines means that
 	  first_mod_line can no longer be used to reliably detect the
 	  first modified line in a paragraph, since a line unmodified by
 	  justify_format() may get a space tacked onto the end of it
diff --git a/src/nano.c b/src/nano.c
index b6d759623e4734af4c4eaf2139dc07e659b14fe3..f580f159925cf2cde8d47062d6e41644a97312e3 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2594,14 +2594,25 @@ int do_justify(int full_justify)
 	    /* If the line we were on before still exists, and it was
 	     * not the last line of the paragraph, add a space to the
 	     * end of it to replace the one removed or left out by
-	     * justify_format(). */
-	    if (current->prev != NULL && par_len > 1) {
+	     * justify_format().  If it was the last line of the
+	     * paragraph, and justify_format() left a space on the end
+	     * of it, remove the space. */
+	    if (current->prev != NULL) {
 		size_t prev_line_len = strlen(current->prev->data);
-		current->prev->data = charealloc(current->prev->data,
+
+		if (par_len > 1) {
+		    current->prev->data = charealloc(current->prev->data,
 			prev_line_len + 2);
-		current->prev->data[prev_line_len] = ' ';
-		current->prev->data[prev_line_len + 1] = '\0';
-		totsize++;
+		    current->prev->data[prev_line_len] = ' ';
+		    current->prev->data[prev_line_len + 1] = '\0';
+		    totsize++;
+		} else if (par_len == 1 &&
+			current->prev->data[prev_line_len - 1] == ' ') {
+		    current->prev->data = charealloc(current->prev->data,
+			prev_line_len);
+		    current->prev->data[prev_line_len - 1] = '\0';
+		    totsize--;
+		}
 	    }
 	}