diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index 72b692ecc936cba793b6cf0a28e3259e6e39dd9d..8a8fe19af994bdd250c25ac1cab18ca7c8d0147b 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -674,6 +674,8 @@ class SimpleSAML_Utilities {
 	 * If an language includes a region, then the result will include both the language with the region
 	 * and the language without the region.
 	 *
+	 * The returned array will be in the same order as the input.
+	 *
 	 * @return An associative array with each language and the score for that language.
 	 */
 	public static function getAcceptLanguage() {
@@ -710,6 +712,9 @@ class SimpleSAML_Utilities {
 				}
 			}
 
+			/* Remove the old key to ensure that the element is added to the end. */
+			unset($ret[$l]);
+
 			/* Set the quality in the result. */
 			$ret[$l] = $q;