The Midnight Library begins with Nora Seed in elementary school, playing chess with the school librarian Mrs. Elm, and discussing different moves in the game. The story then skips ahead to Nora's life as a thirty-five-year-old adult. In the span of a day, she is fired from her job at a music store and then loses a music student because she misses their scheduled lesson. After this, she returns home to find out that her cat has died. Reflecting on how lonely she is, she recalls her fractured relationship with her brother and the engagement she broke off. She feels that she has no remaining connection to the world and decides to end her life. She takes an overdose of pills and subsequently passes out.
She wakes up in a strange library run by Mrs. Elm, who appears exactly as Nora recalls her. Mrs. Elm informs her that she is in the "Midnight Library," a place in which people are given the opportunity to explore the possibilities within the lives they did not lead. She hands her a book titled the "Book of Regrets" which contains all of the things she has ever regretted. Some are small and concrete, while others are larger and more abstract. She begins to explore the parallel lives that she chose not to lead.
In the first of these lives, she owns a pub with Dan, who she used to date. In this life, she chose to go through with their engagement and also help Dan pursue his dream of owning a bar. She helps close up after a trivia night has just concluded. She quickly discovers that this life is less than ideal. Dan is somewhat rude to her and resentful of the things she says. She learns that he has had an affair in this timeline. She returns to the library, frustrated that this life was not what she envisioned.
She enters into another life in which she kept her cat inside. She assumed this would prevent her cat from dying, as she thought it had been struck by a car. Instead, she learns that her cat actually had a health condition that shortened its lifespan, so in that timeline, it actually died years earlier. She complains that Mrs. Elm keeps leading her to lives that are unhappy. She travels to another timeline in which she moved to Australia to be closer to her best friend Izzy. In that life, she finds out that Izzy has recently died in a car accident.
She continues to explore other lives. In one, she didn't quit swimming in high school and competed at the Olympic level. She is close with her brother and delivers motivational speeches. She discovers that in this life her father is still alive but her mother is not, as she became an alcoholic after Nora's father left her. She gives a speech and talks about her idea of life as a tree, with multiple branches being created from various decisions. She adds that the idea of a "successful" life is fictional, as every version of someone's life contains frustrations.
She goes back to the library and finds that there is a system error. The library is having issues because she might be dying and the space will cease to exist if she actually dies. She travels to a life in which she became a glaciologist. She talks with a coworker and then is told to keep watch for polar bears. She has a terrifying experience in which she narrowly avoids being attacked. She also meets Hugo Lefebvre, someone else who is traveling through various iterations of his life. They have a disappointing sexual encounter and she goes back to the library.
In another life, she is a famous rockstar, as she stayed in the band she started with her brother. In that life, her brother is no longer alive, but she is rich and famous, admired by many people for her musical talent. She also finds that she is dating a famous movie star. She goes on a podcast and learns more details about her music life. She returns to the library, frustrated with the process, and grows increasingly despondent about finding a good life to live.
She lives multiple other lives. In one, she works at a dog shelter with her boyfriend, who has long hair and treats her kindly. In another, she has a troubled marriage and owns a vineyard. She hops around into many other possible lives before settling into one she finds meaningful and fulfilling. In her supposed best life, she is married to her neighbor Ash, teaches philosophy, and has a daughter. She spends a long time in this life, considering how perfect it is and slowly slipping further and further into it. One day, she comes across a boy who was her piano student in her original life as he is being arrested. She realizes how important their music lessons were to him and the outcome of his life. She returns to her home and departs from that life back to the library.
The library starts to come apart as Nora decides she wants to live. She escapes the library and returns to her original life. She is able to find her neighbor before passing out. She wakes up in the hospital and talks to her brother. They patch things up over the course of a conversation. She also contacts the mother of the student whose lesson she missed and tells her that her son is extremely talented and she won't forget their lesson time again. Aware of all of the possibilities in her life, Nora feels happy again. She visits the real Mrs. Elm in a nursing home and they share a nice moment over a game of chess.