In 1859, the Austrians, thanks to a more competent leadership and limited army reforms, defeat the French at Solferino. While not a crippling lost, it is enough to force Napoleon III to negotiate, and withdraw from Italy, leaving it under Austrian sphere, and leavind Sardinia to its fate. This is enough to turn Napoleon into a rabid anti-Austrian, seeking to avenge this humiliation. Bismarck sees a golden opportunity, and being in need of a southern support flank, begins negotiations in around 1865.
In them, the two make deals on spheres of influence. Belgium shall be aknowledged as French sphere, and Napoleon III. will be allowed to annex Luxmbourg with German support. In Italy, Nice, Aosta valley and upper Savoy will become part of France, while the rest of Sardinia, the other smaller states such as Tuscany and Austrian Lombardy will form a North Italian federation, possibly to be lead and joined by the Pope, and under French influence. In exchange, Napoleon will agree with a unified Germany under Prussia, as long as no Greater Garmany ideas are tried. Details here might be different, but essentially the two would be trying to find a way so that the French gain enough to not be totally outstrenght by the united German state.
A war occurs and the new allies win. Napoleon perhaps makes a few ambitious statements towards Baden and Bavaria, to help them along in joining Germany. Britain is extremely unhappy with the idea of the balance of power in Benelux being so changed, deffinetly trying to keep French hands off Belgium, and might well decide that an alliance with the now weaker Austria is neede to counter this new power block, ironnically somewhat recreating the alliance from the war of Austrian succession. With this new alliance, the French and Germans decide that together they are much safer from such an alliance attempting to undue their gains, and formalize their own alliance.
Such an alliance would certainly have many possible problems ahead of it (question of Alsace-Lorraine, the Spanish succession and so on), but if there is a big enough outside threat, it could in theory last for quite some time.