Midcap and Smallcap indices also participated in the rally but underperformed the benchmark, reflecting investors' preference for quality companies amid rich valuations.