Prim's Algorithm produces Minimum Spanning Tree
So, we replace $e'$ in $S$ with $e$ from $T$, and obtain a new spanning tree $S'$.
From the method of construction of $T$, it follows that the weight of $e$ can not exceed that of $e'$.
So the total weight of $S'$ does not exceed the total weight of $T$.
Also, $S'$ has one more edge in common with $T$ than $S$ has.
We repeat the above procedure, and repeatedly change edges of $S$ for edges of $T$, and each time the weight of the intermediate graph does not exceed that of $T$.
Thus the weight of $T$ does not exceed that of $S$, contradicting the definition of $S$.
Hence $T$ must be a minimum spanning tree.