A gas turbine engine includes a compressor section and a turbine section together defining a core air flowpath. The rotary component is rotatable with the compressor section and the turbine section. The gas turbine engine additionally includes an electric machine rotatable with the rotary component and positioned coaxially with the rotary component at least partially inward of the core air flowpath. The electric machine is flexibly mounted to a static frame member, or flexibly coupled to the rotary component, or both, such that the electric machine is mechanically isolated or insulated from various internal and external forces on the gas turbine engine.