When Earth goes near the Sun, its velocity increases and when it goes far from the Sun its velocity decreases. Then why according to Kepler's law is the time period $T^2 \propto a^3$, where $a$ is the radius? As we know velocity has an effect on time period.

• Your second sentence doesn't seem to relate to your first... but if I've interpreted correctly, you're asking why Kepler's Law states that the time period doesn't depend on the speed of the planet, when surely a faster-moving planet will have a shorter time period? – gj255 Dec 25 '14 at 21:29

Because this radius $a$ is the semi-major axis of the elliptical orbit. It is not the instantaneous distance.
Eccentricity plays no role in determining the period of a Keplerian orbit. The period is given by $T = {2 \pi}\sqrt{\frac {a^3}{G(M+m)}}$ where $T$ is the orbital period, $a$ is the semi-major axis of the orbit, $M$ is the mass of the central body, and $m$ is the mass of the orbiting body.
Eccentricity plays a definite role in determining the instantaneous velocity of an object in a Keplerian orbit. The radial distance between the central body and orbiting body ranges from $a(1-e)$ to $a(1+e)$, where once again $a$ is the semi-major axis of the orbit and $e$ is the eccentricity of the orbit. The magnitude of the instantaneous velocity at any point along the orbit is given by the vis viva equation, $v^2 = G(M+m)\left(\frac 2 r - \frac 1 a\right)$.