/u/elos_ more or less answers that question in this answer to a much wider question from a few weeks ago. In short, it was the mutual threat of a militaristic, expansionist Germany that lead them to ally, but the whole thing's worth a read for all the in depth context he provides.
It had to do with the Germans, and more specifically, the Berlin Congress after the Russian-Ottoman war. It was a revision of the treaty of San Stefano that was initially signed at the end of the war. Russia (victorious side in the war) was unhappy by the outcome of the congress of Berlin and it greatly strained its relationship with Germany. The League of the Three Emperors, an alliance of Germany, Russia, and Austria-Hungary that was signed in 1873, got dissolved in 1878, after the Congress. It got revived in 1881, and then finally dissolved in 1887, due to conflict of interest of Austria-Hungary and Russia in the Balkans (also a consequence of the Berlin Congress). Bismarck signed the secret Reinsurance treaty with Russia in 1887., which was essentially a non-aggression pact.
Bismarck got dismissed in 1888. and Emperor Wilhelm wasn't interested in continuing Bismarck's policies. When the Russians asked for an extension of the treaty in 1890., he refused. He was worried that the provision of the treaty that promised that Germany would remain neutral if Russia would occupy Istanbul (Constantinople) would strain his relations with Britain (because it threatened their colonial interests in the Middle East) and Ottoman Empire(for obvious reasons), if it was made public.
Bismarck's strategy in preceding years was to isolate France diplomatically, with his great fear being a Franco-Russian alliance that would expose Germany on two fronts. France and Germany already had a huge point of contention, Alsace-Lorraine, and the French humiliation in the Franco-Prussian war that they were itching to get revenge for. After 1888., relations between France and Russia started warming up, and after the change of policy with Bismarck's dismissal, well...It made France and Russia natural allies.
In 1892. Triple Alliance was signed between Germany, Austria-Hungary and Italy which guaranteed that they would come to each other's aid in case of an attack by another great power. An alliance between France and Russia was signed the same year.