6. The sequence $\left\{a_{n}\right\}$ is defined as follows:
$$
\begin{array}{l}
a_{1}=1, a_{2}=3, \\
a_{n+2}=2 a_{n+1}-a_{n}+2(n=1,2, \cdots) .
\end{array}
$$

Then the sum of its first $n$ terms is
6. $\frac{1}{3} n\left(n^{2}+2\right)$.

From the given, we have $a_{n+2}-a_{n+1}=\left(a_{n+1}-a_{n}\right)+2$. Therefore, the sequence $\left\{a_{n+1}-a_{n}\right\}$ is an arithmetic sequence with a common difference of 2, and the first term is $a_{2}-a_{1}=2$. Hence, $a_{n+1}-a_{n}=2 n$. Thus,
$$
\begin{array}{l}
a_{n}=\left(a_{n}-a_{n-1}\right)+\cdots+\left(a_{2}-a_{1}\right)+a_{1} \\
=2(n-1)+\cdots+2+1=n(n-1)+1, \\
S_{n}=\sum_{k=1}^{n}[k(k-1)+1]=\sum_{k=1}^{n}\left(k^{2}-k+1\right) \\
=\frac{n(n+1)(2 n+1)}{6}-\frac{n(n+1)}{2}+n \\
=\frac{1}{3} n\left(n^{2}+2\right) .
\end{array}
$$