Phelps ends career with gold in medley relay