South Africa seal their place in World Test Championship final with a two-wicket win.