Ducati announced earlier that Rossi was leaving the team following a disappointing two-year spell at the Italian squad, where the Italian rider struggled to be competitive, managing just two podiums and no victories so far.
Rossi enjoyed a very successful time at Yamaha, which he joined from Honda at the start of the 2004 season.
With the Japanese squad, the nine-time world champion took the titles in 2004, 2005, 2008 and 2009 and scored 46 victories before leaving for Ducati at the end of 2010.
Rossi will rejoin Yamaha alongside Spaniard Jorge Lorenzo, who was his team-mate at the team before he decided to leave for Ducati.
The Italian rider has signed a two-year deal with Yamaha.
"This announcement is once again excellent news for Yamaha," said Yamaha's Lin Jarvis. "In June we were able to sign Jorge Lorenzo for the 2013-14 campaign and now we are able to confirm Valentino Rossi for the next two years.
"In doing so we have been able to put together the strongest possible team to challenge for victories and to promote the Yamaha brand.
"The target for the future is obvious and we will do our utmost to achieve our goals.
"I have no doubt that with the experience, knowledge, skills and speed of these two great champion riders we will be able to challenge for many race wins and for the 2013 & 2014 World Championship titles."