Wales edge out Scotland in dramatic finish