For two n-by-n matrices A and B, it was known before that their numerical radii satisfy the inequality w(AB)≤4w(A)w(B), and the equality is attained by the 2-by-2 matrices A=[0 00 1] and B = [1 00 0]. Moreover, the constant "4" here can be reduced to "2" if A and B commute, and the corresponding equality is attained by A=I2 ⊗ [0 00 1] and B=[0 00 1] ⊗ I2. In this paper, we give a complete characterization of A and B for which the equality holds in each case. More precisely, it is shown that w(AB)=4w(A)w(B) w(AB)=2w(A)w(B) for commuting A and B) if and only if either A or B is the zero matrix, or A and B are simultaneously unitarily similar to matrices of the form [0 0 0 a] ⊗ A′ and [b 00 0] × B′ (resp., (Formula presented.) ⊗ A′ and (Formula presented.) ⊗ B′ with w(A′)≤|a|/2 and w(B′)≤|b|/2. An analogous characterization for the extremal equality for tensor products is also proven. For doubly commuting matrices, we use their unitary similarity model to obtain the corresponding result. For commuting 2-by-2 matrices A and B, we show that w(AB)=w(A)w(B) if and only if either A or B is a scalar matrix, or A and B are simultaneously unitarily similar to (Formula presented.) and (Formula presented.) with |a1|≥|a2| and |b1|≥|b2|.