Memphis Depay had given Barca the lead before Luuk de Jong scored his first goal for the club since joining from Sevilla on the final day of the summer transfer window, but Ansu stole the show with his 10-minute cameo.
Barca came into the match with just one win in five across all competitions and sources told ESPN recently that the club were exploring alternative options to Koeman as manager.
But the hosts raced out of the blocks and were ahead after just six minutes when Memphis won and converted a penalty following a clumsy challenge from Levante's Nemanja Radoja.
Barca were 2-0 up nine minutes later thanks to fellow Netherlands forward De Jong. Sergino Dest was key in the goal as he led a counterattack and fed De Jong, who coolly slotted the ball past Levante goalkeeper Aitor Fernandez.
However, the loudest cheer of the day was reserved for the 80th minute, when Ansu replaced De Jong.
Despite the feel-good factor in Camp Nou with Ansu's return, Barca had Marc-Andre ter Stegen to thank for maintaining their advantage as he was called upon to make two late saves.
But Ansu, Barca's new No. 10, made the points safe with the third in stoppage time to evoke an even more enthusiastic reaction from the supporters as he went into the crowd to celebrate with the doctor who helped his recovery from a serious knee injury.
I didn't imagine a comeback like this," Ansu said after the match. "When we play at home we always have to win. I am happy with the victory. We still have a long way to go.
"I want to show my appreciation to the doctors and the physios that have been with me throughout this process. And also to the fans, who were incredible."
Asked he felt any pressure at wearing the No. 10 shirt vacated by Lionel Messi, he said: "Not for me. It's an honour to wear it after Leo, I'm grateful to the club and the captains for giving me the chance to wear it.
"It's not pressure. I am grateful to take on a number that has given this club so much."