MOROCCO 27 Mar 2015 (AFP) - The 31-year-old Scot produced six birdies to add to his first round 72 to join Australia's Richard Green, Spain's Rafael Cabrera-Bello and Welshman Oliver Farr on six-under-par 138 at Golf du Palais Royal.
Farr had looked set to hold the overnight lead sitting seven under par until a bogey at the 18th saw him sign for a 68.
Earlier Cabrera-Bello had fired five birdies for two bogeys in a round of 69, one better than Green's second-round effort.
"The last few months have been frustrating," said Ramsay, who had missed four cuts in five events to date in 2015 and had to withdraw injured in Dubai.
South Africa's George Coetzee and England's Tommy Fleetwood are still in contention to secure a place in the Masters as Andy Sullivan, Alexander Levy, Marcel Siem and Ross Fisher all missed out in Morocco.
Coetzee and Fleetwood need to win the Hassan Trophy to book a trip to Augusta in a fortnight's time and reached halfway just one and three shots off the lead respectively.
But Sullivan, Levy, Siem and Fisher all missed the halfway cut in Agadir, with 2013 champion Siem crashing from joint-sixth overnight with a second round of 79.
Second round scores on Friday in the European Tour's Trophee Hassan II (par 72):
138 - Rafa Cabrera-Bello (ESP) 69-69, Richard Green (AUS) 68-70, Richie Ramsay (SCO) 72-66, Oliver Farr (WAL) 70-68
139 - Richard Bland (ENG) 69-70, Pablo Larrazabal (ESP) 70-69, Chris Wood (ENG) 67-72, Ben Evans (ENG) 69-70, George Coetzee (RSA) 67-72
140 - David Howell (ENG) 70-70, Kevin Phelan (IRL) 70-70, Jaco Van Zyl (RSA) 69-71, Max Orrin (ENG) 70-70, Anthony Wall (ENG) 68-72, Joakim Lagergren (SWE) 72-68, Jorge Campillo (ESP) 71-69, David Drysdale (SCO) 67-73