Just like Italy in WW1
I am nitpicking, but I don't think Italy joined the war when Allied win was clear - it joined in 1915 - if anything, the Middle Powers seemed to be winning (in Europe). Germans had just pushed the Russians back out and captured much Polish land. Belgium was German territory with all resistance crushed, and the Germans were getting close to Paris.
I think the country you want is Romania - joined in 1916, but left the war in December 1917, since Russia stopped fighting. But then, on November 10, 1918, Romania rejoined the war, and ended it a day later.