We prove a sufficient stochastic maximum principle for the optimal control of a regimeswitching diffusion model. We show the connection to dynamic programming and we apply the result to a quadratic loss minimization problem, which can be used to solve a mean-variance portfolio selection problem. . where b n : [0, T ]×R N ×R P ×I → R and σ nm : [0, T ]×R N ×R P ×I → R are given continuous functions for n, m = 1, . . . , N . Using A ⊤ to denote the transpose of a matrix A, set b(t) := (b 1 (t), . . . , b N (t)) ⊤ and σ(t) := (σ nm (t)) N n,m=1 . We consider a performance criterion defined for each x ∈ R N asf (t, X(t), u(t), α(t)) dt + h(X(T ), α(T )) X(0) = x, α(0) = i 0 ,