Farhan Qureshi (R. Madhavan), Raju Rastogi (Sharman Joshi), and Rancchoddas "Rancho" Shyamaldas Chanchad (Aamir Khan) are three engineering students who share a room in a hostel at the Imperial College of Engineering, one of the best colleges in India. While Farhan and Raju are average students from modest backgrounds, Rancho is from a rich family. Farhan wants to become a wildlife photographer, but has joined engineering college to fulfil his father's wish. Raju on the other hand wants to uplift his family fortunes. Rancho is a wealthy genius who studies for the sheer joy of it. However, Rancho's passion is for knowledge and taking apart and building machines rather than the conventional obsession of the other students with exam ranks. With his different approach Rancho incurs the wrath of dean of college, Professor Viru Sahastrabudhhe aka ViruS (Boman Irani). Rancho irritates his lecturers by giving creative and unorthodox answers, and confronts ViruS after fellow student Joy Lobo hangs himself in his dormitory room. Rancho denounces the rat race, dog-eat-dog, mindless rote learning mentality of the institution, blaming it for Lobo's death.
Threatened by Rancho's talent and free spirit, ViruS labels him an "idiot" and attempts on a number of occasions to destroy his friendship with Farhan and Raju, warning them and their parents to steer clear of Rancho. In contrast, ViruS model student is Chatur Ramalingam or "Silencer", (Omi Vaidya) who sees a high rank at the prestigious college as his ticket to higher social status, corporate power, and therefore wealth. Chatur conforms to the expectations of the system. Rancho humiliates Chatur, who is awarded the honor of making a speech at an award ceremony, by substituting obscenities into the text, which has been written by the librarian. As expected, Chatur mindlessly memorises the speech, without noticing that anything is amiss, partly aided by his lack of knowledge on Hindi. His speech becomes the laughing stock of the audience, infuriating the authorities in the process.
Meanwhile, Rancho also falls in love with ViruS' medical student daughter Pia (Kareena Kapoor) when he, Raju and Farhan crash her sister's wedding banquet in order to get a free meal, in the process further infuriating ViruS.
The three students continue to anger ViruS, although Rancho keeps coming first in every exam, while Chatur is always second, and Farhan and Raju are inevitably in the last two positions. The tensions come to a head when the three friends, who are already drunk, break into ViruS's house at night to allow Rancho to propose to Pia, and then urinate on a door inside the compound before running away when ViruS senses intruders. The next day, ViruS threatens to expel Raju lest he talks on the other two. Unable to choose between betraying his friend or letting down his family, Raju jumps out of the 3rd floor window and lands on a courtyard, but after extensive care from Pia and his roommates, awakes from a coma.
The experience has changed Farhan and Raju, and they adopt Rancho's outlook. Farhan decides to pursue his love of photography, while Raju takes an unexpected approach for an interview for a corporate job. He attends in plaster and a wheelchair and gives a series of non-conformal and frank answers. However, ViruS is unsympathetic and vows to make the final exam as hard as possible so that Raju is unable to graduate. Pia hears him and angrily confronts him, and when ViruS gives the same ruthless reply he gives to his students, Pia reveals that Viru's son and her brother was not killed in an accident but committed suicide in front of a train and left a letter because ViruS had forced him to pursue a career in engineering over his love for literature; ViruS always mentioned that he unsympathetically failed his son on the ICE entrance exams over and over to every new intake of ICE students. After this, Pia walks out on the family home, and takes ViruS' spare keys with her. She tells Rancho of the exam, and he and Farhan break into ViruS's office and steal the questions and give it to Raju, who with his new-found attitude, is unconcerned with the prospect of failing, and refuses to cheat. However, ViruS catches the trio and expels them on the spot. However, they earn a reprieve when Viru's pregnant elder daughter Mona (Mona Singh) goes into labour at the same time. A heavy storm cuts all power and traffic, and Pia is still in self-imposed exile, so she instructs Rancho to deliver the baby in the college common room via Voice over IP, after Rancho restores power using car batteries and a power inverter that Rancho had made up and ViruS had mocked. He then delivers the baby with the help of a cobbled-together Vacuum extractor.
After the baby is apparently stillborn, Rancho resuscitates it. ViruS reconciles with Rancho and his friends and allows them to take their final exams and they graduate. Rancho comes first and is awarded ViruS's pen, which the professor had been keeping for decades before finding a brilliant enough student to gift it to.
Their story is framed as intermittent flashbacks from the present day, ten years after Chatur vowed revenge on Rancho for embarrassing him at the speech night and promised to become more successful than Rancho a decade later. Having lost contact with Rancho, who disappeared during the graduation party and went into seclusion, Raju and Farhan begin a journey to find him. They are joined by Chatur, now a wealthy and successful businessman, who joins them, confident that he has surpassed Rancho. Chatur is also looking to seal a deal with a famous scientist and prospective business associate named Phunsukh Wangdu. Chatur sees Wangdu, who has hundreds of patents, as his ticket to further social prestige. When they find Rancho's house, they walk into his father's funeral, and find a completely different Rancho (Jaaved Jaffrey). After accusing the new man of stealing their friend's identity, the host pulls a gun on them, but Farhan and Raju turn the tables by seizing his father's ashes and threatening to flush them down a toilet. The householder capitulates and says that their friend was a destitute servant boy who loved learning, while he, the real Rancho, was a lazy wealthy child who disliked study, so the family agreed to let the servant boy study in Rancho's place instead of labouring. In return, the real Rancho would pocket the qualifications and the benefits thereof, while the impersonator would sever all contact with the world and start a new life. The real Rancho reveals that their friend is now a schoolteacher in Ladakh.
Raju and Farhan then find Pia, and take her from her wedding to Suhas, by performing the same tricks with his material possessions, and having Raju turn up to the ceremony disguised as the groom and eloping with Pia in public. When they arrive in Ladakh, they see a group of enthusiastic children who are motivated by love of knowledge. Pia and the fake Rancho rekindle their love, while Chatur mocks and abuses him the schoolteacher before walking away. When his friends ask what his real name is, he reveals it is Phunsukh Wangdu and phones Chatur, who has turned his back, to turn around and meet his prospective business partner. Chatur is horrified and falls to his knees, accepts his defeat and continues to plead his case with Phunsukh to establish the business relationship he was after.