diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 52874228d2865fc076dd9ca89a22cb66fb66668c..1feccba01fb29e7f2c775dd9262a21186cf5c4c7 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -7044,7 +7044,7 @@ static int sip_hangup(struct ast_channel *ast)
 				}
 
 				/* Send a hangup */
-				if (ast_channel_state(oldowner) == AST_STATE_UP) {
+				if (ast_channel_state(oldowner) == AST_STATE_UP || p->invitereplaces) {
 					transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
 				}
 
@@ -8591,6 +8591,7 @@ struct sip_pvt *sip_alloc(ast_string_field callid, struct ast_sockaddr *addr,
 	make_our_tag(p);
 	p->ocseq = INITIAL_CSEQ;
 	p->allowed_methods = UINT_MAX;
+	p->invitereplaces = 0;
 
 	if (sip_methods[intended_method].need_rtp) {
 		p->maxcallbitrate = default_maxcallbitrate;
@@ -24917,6 +24918,8 @@ static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, st
 	struct ast_channel *replacecall = p->refer->refer_call->owner;	/* The channel we're about to take over */
 	struct ast_channel *targetcall;		/* The bridge to the take-over target */
 
+	p->refer->refer_call->invitereplaces = 1;
+
 	/* Check if we're in ring state */
 	if (ast_channel_state(replacecall) == AST_STATE_RING)
 		earlyreplace = 1;
@@ -25026,6 +25029,11 @@ static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, st
 		ast_channel_unlock(c);
 	}
 
+	/* Clear SIP_DEFER_BYE_ON_TRANSFER after the masq to avoid delay hanging up replaced channel */
+	sip_pvt_lock(p);
+	ast_clear_flag(&p->refer->refer_call->flags[0], SIP_DEFER_BYE_ON_TRANSFER);
+	sip_pvt_unlock(p);
+
 	/* c and c's tech pvt must be unlocked at this point for ast_hangup */
 	ast_hangup(c);
 	/* this indicates to handle_request_do that the owner channel has already been unlocked */
diff --git a/channels/sip/include/sip.h b/channels/sip/include/sip.h
index 6b448bf075716bbe8045a580c5b39ea12a0f65f2..87a8c68e3259429b7901b2f24c519ece5778c50d 100644
--- a/channels/sip/include/sip.h
+++ b/channels/sip/include/sip.h
@@ -1100,6 +1100,7 @@ struct sip_pvt {
 	                                       */
 	unsigned short req_secure_signaling:1;/*!< Whether we are required to have secure signaling or not */
 	unsigned short natdetected:1;         /*!< Whether we detected a NAT when processing the Via */
+	unsigned short invitereplaces:1;      /*!< Whether we are doing an Invite: Replaces */
 	int timer_t1;                     /*!< SIP timer T1, ms rtt */
 	int timer_b;                      /*!< SIP timer B, ms */
 	unsigned int sipoptions;          /*!< Supported SIP options on the other end */