diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 58a4879b00a9dc4318553726524a7432fb8ec0bd..e2f79592d79f9d7e8d81c801d678f9fce672011d 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -2658,6 +2658,18 @@ void ast_channel_internal_swap_uniqueid_and_linkedid(struct ast_channel *a, stru
  */
 void ast_channel_internal_swap_topics(struct ast_channel *a, struct ast_channel *b);
 
+/*!
+ * \brief Swap endpoint_forward between two channels
+ * \param a First channel
+ * \param b Second channel
+ * \return void
+ *
+ * \note
+ * This is used in masquerade to exchange endpoint details if one of the two or both
+ * the channels were created with endpoint
+ */
+void ast_channel_internal_swap_endpoint_forward(struct ast_channel *a, struct ast_channel *b);
+
 /*!
  * \brief Swap snapshots beteween two channels
  * \param a First channel
diff --git a/main/channel.c b/main/channel.c
index 7e12f304923f337917fd16141380c4fef185e1f2..4fb226d491a741286804e6d20f7faf42e65d6e8e 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -6790,6 +6790,11 @@ static void channel_do_masquerade(struct ast_channel *original, struct ast_chann
 	/* Make sure the Stasis topic on the channel is updated appropriately */
 	ast_channel_internal_swap_topics(clonechan, original);
 
+	/* Swap endpoint forward so channel created with endpoint exchanges its state
+	 * with other channel for proper endpoint cleanup.
+	 */
+	ast_channel_internal_swap_endpoint_forward(clonechan, original);
+
 	/* The old snapshots need to follow the channels so the snapshot update is correct */
 	ast_channel_internal_swap_snapshots(clonechan, original);
 
diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c
index 30d39097e0a7dde03839f9c1db9a14844289ca31..22a2bb6b313a9385872661dbbb8f9015647687a4 100644
--- a/main/channel_internal_api.c
+++ b/main/channel_internal_api.c
@@ -1438,6 +1438,15 @@ void ast_channel_internal_swap_topics(struct ast_channel *a, struct ast_channel
 	b->channel_forward = forward;
 }
 
+void ast_channel_internal_swap_endpoint_forward(struct ast_channel *a, struct ast_channel *b)
+{
+	struct stasis_forward *temp;
+
+	temp = a->endpoint_forward;
+	a->endpoint_forward = b->endpoint_forward;
+	b->endpoint_forward = temp;
+}
+
 void ast_channel_internal_swap_snapshots(struct ast_channel *a, struct ast_channel *b)
 {
 	struct ast_channel_snapshot *snapshot;