Among the wonderful signs which God, the Exalted, has brought forth through the hands of the Commander of the faithful, 'Ali b. Abi Talib, is one, the reports of which have become widespread among the biographers and historians ('ulama' al-siyar wa al-athar) and about which the poets have composed verses (namely) when he, peace be on him, sent back the sun (to its earlier position) on two occasions, once during the life of the Prophet and another time after his death.
The account of it being sent back on the first occasion has been reported by Asma' daughter of 'Umays, Umm Salama, the wife of the Prophet, may God bless him and his family, Jabir b. 'Abd Allah al-Ansari, Abu Sa'id al-Khudri and a group of the Companions.
One day the Prophet, may God bless him and his family, was in his house and 'Ali, peace be on him, was in front of him when Gabriel, peace be on him, came to him to speak privately to him about God. When inspiration closed in upon him, he used the thigh of the Commander of the faithful, peace be on him, as a pillow. He did not raise his head from it until the sun had set. Thus he compelled the Commander of the faithful, peace be on him, (to remain) in that position. So he prayed the afternoon prayer sitting, giving a nod (with his head) for his bowing and prostration. When (the Apostle) awoke" from his trance, he said to the Commander of the faithful: "Have you missed the afternoon prayer?"
"I could not pray it standing because of your position, Apostle of God, and the circumstances of hearing inspiration which I was in," he answered.
"Ask God to send the sun back for you so that you may pray it standing at its proper time just as (it was) when you missed being able to do it," he told him. "God, the Exalted, will answer you because of your obedience to God and to His Apostle."
The Commander of the faithful, peace be on him, asked God to send back the sun. It was sent back for him so that it came into its position in the sky at the time for the afternoon prayer. The Commander of the faithful, peace be on him, prayed the afternoon prayer at its proper time. Then it set. [Asma' reported:]
By God we heard it at it's setting, screeching like the screech of the saw in wood.
****************
Its being sent back for him after the Prophet, may God bless him and his family, was when he wanted to cross the Euphrates at Babylon, many of his followers were occupied in taking their animals and baggage across. He, peace be on him, prayed the afternoon prayer himself with a group who were with him. The people did not finish their crossing and many of them missed the time of the prayer. The people recalled the merit of being together for that (prayer) and they spoke about that. When he heard their talk about it, he asked God to send back the sun so that all his followers might be together to perform the afternoon prayer at its proper time. God, the Exalted, answered him by sending back the sun for him. The horizons became such as they are for the time of the afternoon prayer. When the people had said the final greeting (at the end of the prayer), the sun disappeared and a violent throbbing was heard from it which terrified the people. They became profuse in their glorification of God, in their declarations of His uniqueness, and in seeking forgiveness from him, and in praising God for the favour which he had shown to them.
The reports of that have reached the (distant) horizons and its account is widespread among the people. Concerning that al-Sayyid b. Muhammad al-Himyari, may God have mercy on him, recited:
The sun was sent back for him when he missed the time of the afternoon prayer and sunset had drawn near.
So that its light shone (the same as) at its time for the afternoon. Then it fell like a shooting star.
For him it was sent back another time at Babylon. It has not been sent back for any Arab creature,
Only so that his first (view of it) may be mixed with his later (view of it) and so that it being sent back may be an explanation of a wondrous matter.
source : http://www.imamalinet.net