RAW: A miss is a miss, and you need to be hit
Deflect missiles requires you to be hit by an attack, and as the attack missed you are not hit.
[...] you can use your reaction to deflect or catch the missile when you are hit by a ranged weapon attack.
--- Player's Handbook p. 78
The game does not make a distinction or special case for 'near misses'. The rule is simply:
If the total of the roll plus modifiers equals or exceeds the target's Armor Class (AC), the attack hits.
--- Player's Handbook p.194
Your DM may allow you to anyway, however there are no solid rules for doing so. The closest are the Success At a Cost guidelines on page 242 of Dungeon Master's Guide which might allow a 'near' success to be a hit at some detriment to the attacker (the who made the roll). It might be difficult to argue on a ranged attack (difficult to overextend on one etc.) and it isn't quite the effect you're after. Also if you are likely to be target by more ranged attacks this round, using your reaction to only catch the missile is of limited value.
If allowing such an act, you should still be required to 'reduce the damage' of the attack to 0 before throwing it back to prevent flinging back near-miss cannonballs and ballista-bolts shenanigans.