Smith avoids last-lap wreck to win