Narrated Anas: A man came to the Prophet on a Friday while he (the Prophet) was delivering a sermon at Medina, and said, "There is lack of rain, so please invoke your Lord to bless us with the rain." The Prophet looked at the sky when no cloud could be detected. Then he invoked Allah for rain. Clouds started gathering together and it rained till the Medina valleys started flowing with water. It continued raining till the next Friday. Then that man (or some other man) stood up while the Prophet was delivering the Friday sermon, and said, "We are drowned; Please invoke your Lord to withhold it (rain) from us" The Prophet smiled and said twice or thrice, "O Allah! Please let it rain round about us and not upon us." The clouds started dispersing over Medina to the right and to the left, and it rained round about Medina and not upon Medina. Allah showed them (the people) the miracle of His Prophet and His response to his invocation.
Source: Sahih Bukhari Volume 8, Book 73, Number 115