Farhan Qureshi (R.Madhavan) and Raju Rastogi (Sharman Joshi) are students at the prestigious Imperial College of Engineering (ICE). Farhan's passion is wildlife photography, but he pursues an engineering degree to appease his father. Raju chooses engineering with hopes of improving his family's financial situation, but his lack of self-confidence results in poor grades. Their third roommate and friend, Ranchodas 'Rancho' Shamaldas Chanchad (Aamir Khan), has an immense interest in engineering, and invents in his spare time. After giving unorthodox answers in class, Rancho faces scrutiny from the college's director, Dr. Viru Sahastrabuddhe (Boman Irani), known as "Virus", whose traditional philosophies on education and learning contrast sharply with Rancho's atypical ideas of teaching. Virus is shown to be extremely strict — a trait that indirectly caused his own son's suicide after putting him under excessive pressure.
Rancho eventually falls in love with Pia (Kareena Kapoor), Virus' younger daughter, who is a medical student in residency at the city's hospital. He also scores the highest marks on exams out of his class, much to the dismay of both Virus and Chatur, an arrogant Tamil student who also despises Rancho. One night, Rancho, Farhan, and Raju drunkenly break into the Sahastrabuddhe household to allow Rancho to confess his love to Pia. After discovering their antics, Virus threatens to expel Raju unless he writes a letter blaming Rancho for the break-in. Unwilling to betray Rancho or disappoint his family, Raju unsuccessfully attempts suicide, and ends up in a coma. After intensive care and support from his friends, Raju recovers just before he successfully interviews for a corporate job.
Farhan has adopted Rancho's outlook and decides to pursue his love of photography. Frustrated at Rancho's influence on Raju and Farhan, Virus conspires to deliberately modify the final exams so that none of them can graduate. However, Pia gives Virus' office keys to Rancho to enable him to get the exam papers. Virus finds them and expels Rancho. The trio, however, earn a reprieve when Virus' pregnant elder daughter Mona (Mona Singh) goes into labour at the same time that a heavy storm cuts off all power and traffic. Despite this, Rancho uses his engineering knowledge to deliver the baby in the college common room. A grateful Virus finally acknowledges Rancho as an extraordinary student, and allows the three to graduate. Rancho then unexpectedly disappears shortly after the ceremony.
Ten years later, Chatur is the vice president of a corporation in the United States, Farhan is a successful photographer, and Raju is married while living a comfortable lifestyle. None of them have heard from Rancho since graduation, and the three reunite at the college campus water tower to find him. They discover that the Rancho they knew was actually "Chote", an orphaned servant to the Chanchad family household in Shimla. When the real Ranchodas (Javed Jaffrey) went to London for four years, his father allowed the servant to fill his son's place - including using his son's full name - and take credits for the degree. With the help of the real Ranchodas, the trio travel to a village school in Ladakh, where Rancho supposedly works as a teacher. On the way there, the three rescue Pia from her arranged wedding at Manali.
Upon arrival in Ladakh, the four find the village school where they see young students' inventions resembling Rancho's own college projects. Raju, Farhan, and Pia then happily reunite with Rancho on a sandbar, where Rancho and Pia kiss. Assuming Rancho to just be a school teacher, Chatur forces him to concede that he is less successful than Chatur. Shortly after, Rancho reveals that he became a scientist (while also teaching young children when he's not researching), and that his real name is Phunsukh Wangdu. Much to Chatur's horror, this also happens to be the name of a wealthy client that Chatur had spent a year trying to find and sign a business deal with.