Defoe bagged a brilliant second-half double - and could have had more - to cancel out Mido's first-half Boro opener.
Afonso Alves should have put Boro in front inside the first five minutes at Fratton Park. Former Pompey midfielder Gary O'Neil caught out ex-team-mate Sol Campbell with a bending ball over the home defence to put Alves in on goal but the Brazilian kicked air six yards out.
Boro benefited from more slack defending by the home side to take the lead midway through the half. Campbell and Younes Kaboul went up to contest the same ball, which bounced off Mido's head and into the feet of Alves.
Alves played the ball back for Mido, who used his body to hold off Kaboul's challenge before finishing neatly past David James for his fourth goal in his last five games.
Pompey almost mustered an equaliser in the dying seconds of the first half when Armand Traore burst down the left wing before whipping in a teasing low cross, which Defoe and Papa Bouba Diop narrowly failed to connect with.
Defoe made amends by levelling the scores 14 minutes after the re-start. Peter Crouch slotted in his diminutive strike partner with an angled pass and Defoe showed a brilliant turn of pace before lashing the ball past Boro goalkeeper Ross Turnbull at his near post.
Boro defender Justin Hoyte produced a dramatic goal-line clearance to deny Defoe a second goal 19 minutes from time.
But there was no stopping England striker Defoe winning the match for Pompey with an excellently taken volley four minutes from time after the visitors had failed to properly clear Crouch's header.
Defoe could even have been celebrating a hat-trick but for a poor miss late on.