For the first time, an analytical solution is derived for the boundary-value problem in the theory of elasticity for a straight edge dislocation axially piercing an elastic sphere. The solution is given by the sum of the well-known stress fields of the dislocation placed in an infinite elastic medium and the image stress fields caused by the presence of the sphere free surface. To get the second term, a classical method of solving the boundary-value problems in elastic sphere is used. It is based on the Trefftz representation of the displacement vector and implies finding vector and scalar harmonic functions. Here these functions are found and expressed analytically in terms of infinite series with Legendre and associated Legendre polynomials. The results are visualized with stress-field maps in different cross sections of the sphere. It is shown that the free surface significantly changes the stress fields with respect to the infinite case and introduces the following new features: the anti-plane shear stress components, the change of the stress sign near the surface, new singularities at the points where the dislocation crosses the surface. The dislocation strain energy in the system is also provided and discussed in detail.