This paper studies a network information flow problem for a multiple-input multiple-output (MIMO) Gaussian wireless network with K users and a single intermediate relay having M antennas. In this network, each user sends a multicast message to all other users while receiving K - 1 independent messages from the other users via an intermediate relay. This network information flow is termed a MIMO Gaussian K-way relay channel. For this channel, it is shown that the optimal sum degrees of freedom (sum-DoF) is KM/K - 1, assuming that all nodes have global channel knowledge and operate in full-duplex. A converse argument is derived by cut-set bounds. The achievability is shown by a repetition coding scheme with random beamforming in encoding and a zero-forcing method combined with self-interference cancelation in decoding. Furthermore, under the premise that all nodes have local channel state information at the receiver only and operate in half-duplex mode, it is shown that a total K/2 DoF is achievable when M=K-1. The key to showing this result is a novel encoding and decoding scheme, which creates a set of network code messages with a chain structure during the multiple access phase and performs successive interference cancelation using side-information for the broadcast phase. One major implication of the derived results is that efficient exploitation of the transmit message as sideinformation leads to an increase in the sum-DoF gain in a multiway relay channel with multicast messages.