Suppose you have excess contribution on year Y, you should ask your plan administrator to have the excess (a) plus earnings (b) taken out, suppose this happens at time T.

if T <= 12/31/Y then
   include (a + b) as income in year Y
else if 01/01/(Y+1) <= T <= 04/15/(Y+1) then
   include a as income in year Y
   include b as income in year Y+1
else if T > 04/15/(Y+1) then
   include a as income in year Y
   include (a + b) as income in year_of(T) /* Yes, double taxation on a */
   pay 10% early distribution penalty if applicable
end

Reference: