For a two year time frame, a good insured savings account or a low-cost short-term government bond fund is most likely the way I would go. Depending on the specific amount, it may also be reasonable to look into directly buying government bonds.
The reason for this is simply that in such a short time period, the stock market can be extremely volatile. Imagine if you had gone all in with the money on the stock market in, say, 2007, intending to withdraw the money after two years. Take a broad stock market index of your choice and see how much you'd have got back, and consider if you'd have felt comfortable sticking to your plan for the duration. Since you would likely be focused more on preservation of capital than returns during such a relatively short period, the risk of the stock market making a major (or even relatively minor) downturn in the interim would (should) be a bigger consideration than the possibility of a higher return. The "return of capital, not return on capital" rule. If the stock market falls by 10%, it must go up by 11% to break even. If it falls by 25%, it must go up by 33% to break even.
If you are looking at a slightly longer time period, such as the example five years, then you might want to add some stocks to the mix for the possibility of a higher return. Still, however, since you have a specific goal in mind that is still reasonably close in time, I would likely keep a large fraction of the money in interest-bearing holdings (bank account, bonds, bond funds) rather than in the stock market.
A good compromise may be medium-to-high-yield corporate bonds. It shouldn't be too difficult to find such bond funds that can return a few percentage points above risk-free interest, if you can live with the price volatility. Over time and as you get closer to actually needing the money, shift the holdings to lower-risk holdings to secure the capital amount.
Yes, short-term government bonds tend to have dismal returns, particularly currently. (It's pretty much either that, or the country is just about bankrupt already, which means that the risk of default is quite high which is reflected in the interest premiums demanded by investors.) But the risk in most countries' short-term government bonds is also very much limited. And generally, when you are looking at using the money for a specific purpose within a defined (and relatively short) time frame, you want to reduce risk, even if that comes with the price tag of a slightly lower return.
And, as always, never put all your eggs in one basket. A combination of government bonds from various countries may be appropriate, just as you should diversify between different stocks in a well-balanced portfolio. Make sure to check the limits on how much money is insured in a single account, for a single individual, in a single institution and for a household - you don't want to chase high interest bank accounts only to be burned by something like that if the institution goes bankrupt.
Generally, the sooner you expect to need the money, the less risk you should take, even if that means a lower return on capital. And the risk progression (ignoring currency effects, which affects all of these equally) is roughly short-term government bonds, long-term government bonds or regular corporate bonds, high-yield corporate bonds, stock market large cap, stock market mid and low cap. Yes, there are exceptions, but that's a resonable rule of thumb.