If possible, let the graph be not connected then there must be at least two vertices $u$ and $v$ which have no path between them. They belongs to two different components.
By the condition : Deg($u$)=$\frac{n-1}{2}$=Deg($v$)
Hence each of them are connected to $2\times \frac {n-1}{2}=n-1$ distinct vertices.
then number of vertices = $n-1+2=n+1$, contradiction. Then the graph must be connected.