Choose a K-flat complex $T^\bullet$ of flat $A$-modules representing $R\Gamma(X, K)$, see More on Algebra, Lemma \ref{more-algebra-lemma-K-flat-resolution}. Denote $T^\bullet \otimes_A \mathcal{O}_X$ the pullback of $T^\bullet$ by the morphism of ringed spaces $(X, \mathcal{O}_X) \to (pt, A)$. There is a natural adjunction map $\epsilon : T^\bullet \otimes_A \mathcal{O}_X \to K$ in $D(\mathcal{O}_X)$. Observe that $T^\bullet \otimes_A \mathcal{O}_X$ is a K-flat complex of $\mathcal{O}_X$-modules with flat terms, see Lemma \ref{lemma-pullback-K-flat} and Modules, Lemma \ref{modules-lemma-pullback-flat}. By Lemma \ref{lemma-factor-through-K-flat} we can find a morphism of complexes $$ T^\bullet \otimes_A \mathcal{O}_X \longrightarrow \mathcal{K}^\bullet $$ of $\mathcal{O}_X$-modules representing $\epsilon$ such that $\mathcal{K}^\bullet$ is a K-flat complex with flat terms. Namely, by the construction of $D(\mathcal{O}_X)$ we can first represent $\epsilon$ by some map of complexes $e : T^\bullet \otimes_A \mathcal{O}_X \to \mathcal{L}^\bullet$ of $\mathcal{O}_X$-modules representing $\epsilon$ and then we can apply the lemma to $e$. Choose a K-injective complex $\mathcal{I}^\bullet$ whose terms are injective $\mathcal{O}_X$-modules representing $M$. Finally, choose a quasi-isomorphism $$ \text{Tot}(\mathcal{K}^\bullet \otimes_\mathcal{O} \mathcal{I}^\bullet) \longrightarrow \mathcal{J}^\bullet $$ into a K-injective complex whose terms are injective $\mathcal{O}_X$-modules. Observe that source and target of this arrow represent $K \otimes_{\mathcal{O}_X}^\mathbf{L} M$ in $D(\mathcal{O}_X)$. At this point, for any open $W \subset X$ we obtain a map of complexes $$ \text{Tot}(T^\bullet \otimes_A \mathcal{I}^\bullet(W)) \to \text{Tot}(\mathcal{K}^\bullet(W) \otimes_A \mathcal{I}^\bullet(W)) \to \mathcal{J}^\bullet(W) $$ of $A$-modules whose composition represents the map $$ R\Gamma(X, K) \otimes_A^\mathbf{L} R\Gamma(W, M) \longrightarrow R\Gamma(W, K \otimes_{\mathcal{O}_X}^\mathbf{L} M) $$ in $D(A)$. Clearly, these maps are compatible with restriction mappings. OK, so now we can consider the following commutative(!) diagram of complexes of $A$-modules $$ \xymatrix{ 0 \ar[d] & 0 \ar[d] \\ \text{Tot}(T^\bullet \otimes_A \mathcal{I}^\bullet(X)) \ar[d] \ar[r] & \mathcal{J}^\bullet(X) \ar[d] \\ \text{Tot}(T^\bullet \otimes_A (\mathcal{I}^\bullet(U) \oplus \mathcal{I}^\bullet(V)) \ar[d] \ar[r] & \mathcal{J}^\bullet(U) \oplus \mathcal{J}^\bullet(V) \ar[d] \\ \text{Tot}(T^\bullet \otimes_A \mathcal{I}^\bullet(U \cap V)) \ar[r] \ar[d] & \mathcal{J}^\bullet(U \cap V) \ar[d] \\ 0 & 0 } $$ By the proof of Lemma \ref{lemma-mayer-vietoris} the columns are exact sequences of complexes of $A$-modules (this also uses that $\text{Tot}(T^\bullet \otimes_A -)$ transforms short exact sequences of complexes of $A$-modules into short exact sequences as the terms of $T^\bullet$ are flat $A$-modules). Since the distinguished triangles of Lemma \ref{lemma-unbounded-mayer-vietoris} are the distinguished triangles associated to these short exact sequences of complexes, the desired result follows from the functoriality of ``taking the associated distinguished triangle'' discussed in Derived Categories, Section \ref{derived-section-canonical-delta-functor}.