The midfielder was a big target of Leeds United during the summer transfer window, with Town chairman Phil Hodgkinson revealing that the club rejected four offers from their Premier League neighbours to sign him.
O'Brien was linked with a move to Elland Road throughout the close season and while Town's resolve was tested, they held firm - and reportedly turned down a fourth and final offer, a financial package worth £13m.
The 22-year-old has now ended speculation over his future by penning a new extended contract.
Head coach Carlos Corberán commented: "It’s a very positive moment for the club, because Lewis is the perfect example of the kind of player we want to create – someone who has graduated from the academy to the first team, becoming an important player for the club.
"Working with Lewis is a privilege for me as head coach, because he never stops working for his team or tires of trying to get better or finding solutions for us within a game. He has in his personality all of the values that I want in one player."
Head of football operations Leigh Bromby added: "This deal shows the intent of our club, and the strategy we’re putting in place going forward. We want our best players to be committed to long-term contracts and hold on to our best talent – of which Lewis is 100 per cent one.
"In a business sense, it also protects the club from low offers from other sides when players begin to enter the final years of a deal. It’s a huge positive for Huddersfield Town.
"It goes without saying that Lewis is an incredibly talented footballer, somebody that we want at our club and somebody that we see driving us forward on the pitch. Lewis’ desire to underline his commitment to Town was also a huge factor in this deal being done, highlighting not only his happiness to tie his future to ours, but the positive direction our club is moving in as a whole."