The main idea behind the present research is to design a state-feedback controller for an underactuated nonlinear rotary inverted pendulum module by employing the linear quadratic regulator (LQR) technique using local approximation. The LQR is an excellent method for developing a controller for nonlinear systems. It provides optimal feedback to make the closed-loop system robust and stable, rejecting external disturbances. Model-based optimal controller for a nonlinear system such as a rotatory inverted pendulum has not been designed and implemented using Newton-Euler, Lagrange method, and local approximation. Therefore, implementing LQR to an underactuated nonlinear system was vital to design a stable controller. A mathematical model has been developed for the controller design by utilizing the Newton-Euler, Lagrange method. The nonlinear model has been linearized around an equilibrium point. Linear and nonlinear models have been compared to find the range in which linear and nonlinear models’ behaviour is similar. MATLAB LQR function and system dynamics have been used to estimate the controller parameters. For the performance evaluation of the designed controller, Simulink has been used. Linear and nonlinear models have been simulated along with the designed controller. Simulations have been performed for the designed controller over the linear and nonlinear system under different conditions through varying system variables. The results show that the system is stable and robust enough to act against external disturbances. The controller maintains the rotary inverted pendulum in an upright position and rejects disruptions like falling under gravitational force or any external disturbance by adjusting the rotation of the horizontal link in both linear and nonlinear environments in a specific range. The controller has been practically designed and implemented. It is vivid from the results that the controller is robust enough to reject the disturbances in milliseconds and keeps the pendulum arm deflection angle to zero degrees.