9. (16 points) Find the sum of all elements in the set
$$
\begin{aligned}
M= & \left\{a \left\lvert\, a=\frac{x+y+z}{t}\right., 3^{x}+3^{y}+3^{z}=3^{t},\right. \\
& x 、 y 、 z 、 t 、 a \in \mathbf{Z}\}
\end{aligned}
$$
Let $x \leqslant y \leqslant z$.
Then $3^{t}=3^{x}+3^{y}+3^{z} \leqslant 3 \times 3^{z}=3^{z+1}$
$$
\Rightarrow t \leqslant z+1 \text {. }
$$

From $3^{t}>3^{z}$, we know $t>z$.
$$
\begin{array}{l}
\text { Hence } z<t \leqslant z+1 \Rightarrow t=z+1 \\
\Rightarrow 3 \times 3^{z}=3^{z+1}=3^{x}+3^{y}+3^{z} \\
\Rightarrow x=y=z=t-1 . \\
\Rightarrow a=\frac{3 t-3}{t}=3-\frac{3}{t} .
\end{array}
$$

Since $a$ and $t$ are both integers, we have $t= \pm 1, \pm 3$.
Therefore, $a=0,2,4,6$, i.e., $M=\{0,2,4,6\}$, and the sum of all its elements is 12.